diff --git a/homeassistant/components/airobot/button.py b/homeassistant/components/airobot/button.py index fba02b6fe1e..6768fa4cf9b 100644 --- a/homeassistant/components/airobot/button.py +++ b/homeassistant/components/airobot/button.py @@ -43,6 +43,13 @@ BUTTON_TYPES: tuple[AirobotButtonEntityDescription, ...] = ( entity_category=EntityCategory.CONFIG, press_fn=lambda coordinator: coordinator.client.reboot_thermostat(), ), + AirobotButtonEntityDescription( + key="recalibrate_co2", + translation_key="recalibrate_co2", + entity_category=EntityCategory.CONFIG, + entity_registry_enabled_default=False, + press_fn=lambda coordinator: coordinator.client.recalibrate_co2_sensor(), + ), ) diff --git a/homeassistant/components/airobot/icons.json b/homeassistant/components/airobot/icons.json index 2ea387512e4..80a8d5b621a 100644 --- a/homeassistant/components/airobot/icons.json +++ b/homeassistant/components/airobot/icons.json @@ -1,5 +1,10 @@ { "entity": { + "button": { + "recalibrate_co2": { + "default": "mdi:molecule-co2" + } + }, "number": { "hysteresis_band": { "default": "mdi:delta" diff --git a/homeassistant/components/airobot/strings.json b/homeassistant/components/airobot/strings.json index ac9f26b2e4c..0615da7897b 100644 --- a/homeassistant/components/airobot/strings.json +++ b/homeassistant/components/airobot/strings.json @@ -59,6 +59,11 @@ } }, "entity": { + "button": { + "recalibrate_co2": { + "name": "Recalibrate CO2 sensor" + } + }, "number": { "hysteresis_band": { "name": "Hysteresis band" diff --git a/tests/components/airobot/snapshots/test_button.ambr b/tests/components/airobot/snapshots/test_button.ambr index d378d5c6e24..26e2875162d 100644 --- a/tests/components/airobot/snapshots/test_button.ambr +++ b/tests/components/airobot/snapshots/test_button.ambr @@ -1,4 +1,52 @@ # serializer version: 1 +# name: test_buttons[button.test_thermostat_recalibrate_co2_sensor-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'button', + 'entity_category': , + 'entity_id': 'button.test_thermostat_recalibrate_co2_sensor', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Recalibrate CO2 sensor', + 'platform': 'airobot', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'recalibrate_co2', + 'unique_id': 'T01A1B2C3_recalibrate_co2', + 'unit_of_measurement': None, + }) +# --- +# name: test_buttons[button.test_thermostat_recalibrate_co2_sensor-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'Test Thermostat Recalibrate CO2 sensor', + }), + 'context': , + 'entity_id': 'button.test_thermostat_recalibrate_co2_sensor', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unknown', + }) +# --- # name: test_buttons[button.test_thermostat_restart-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ diff --git a/tests/components/airobot/test_button.py b/tests/components/airobot/test_button.py index 60ddb2e8e96..529605836a9 100644 --- a/tests/components/airobot/test_button.py +++ b/tests/components/airobot/test_button.py @@ -25,7 +25,7 @@ def platforms() -> list[Platform]: return [Platform.BUTTON] -@pytest.mark.usefixtures("init_integration") +@pytest.mark.usefixtures("entity_registry_enabled_by_default", "init_integration") async def test_buttons( hass: HomeAssistant, snapshot: SnapshotAssertion, @@ -93,3 +93,38 @@ async def test_restart_button_connection_errors( ) mock_airobot_client.reboot_thermostat.assert_called_once() + + +@pytest.mark.usefixtures("entity_registry_enabled_by_default", "init_integration") +async def test_recalibrate_co2_button( + hass: HomeAssistant, + mock_airobot_client: AsyncMock, +) -> None: + """Test recalibrate CO2 sensor button.""" + await hass.services.async_call( + BUTTON_DOMAIN, + SERVICE_PRESS, + {ATTR_ENTITY_ID: "button.test_thermostat_recalibrate_co2_sensor"}, + blocking=True, + ) + + mock_airobot_client.recalibrate_co2_sensor.assert_called_once() + + +@pytest.mark.usefixtures("entity_registry_enabled_by_default", "init_integration") +async def test_recalibrate_co2_button_error( + hass: HomeAssistant, + mock_airobot_client: AsyncMock, +) -> None: + """Test recalibrate CO2 sensor button error handling.""" + mock_airobot_client.recalibrate_co2_sensor.side_effect = AirobotError("Test error") + + with pytest.raises(HomeAssistantError): + await hass.services.async_call( + BUTTON_DOMAIN, + SERVICE_PRESS, + {ATTR_ENTITY_ID: "button.test_thermostat_recalibrate_co2_sensor"}, + blocking=True, + ) + + mock_airobot_client.recalibrate_co2_sensor.assert_called_once()