diff --git a/homeassistant/components/honeywell/const.py b/homeassistant/components/honeywell/const.py index 94455d569cb9ca..d5153a69f65a10 100644 --- a/homeassistant/components/honeywell/const.py +++ b/homeassistant/components/honeywell/const.py @@ -9,7 +9,4 @@ DEFAULT_HEAT_AWAY_TEMPERATURE = 61 CONF_DEV_ID = "thermostat" CONF_LOC_ID = "location" -TEMPERATURE_STATUS_KEY = "outdoor_temperature" -HUMIDITY_STATUS_KEY = "outdoor_humidity" - _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/honeywell/sensor.py b/homeassistant/components/honeywell/sensor.py index c1f70bbdd1fbf3..9542648b996818 100644 --- a/homeassistant/components/honeywell/sensor.py +++ b/homeassistant/components/honeywell/sensor.py @@ -21,7 +21,12 @@ from homeassistant.helpers.typing import StateType from . import HoneywellData -from .const import DOMAIN, HUMIDITY_STATUS_KEY, TEMPERATURE_STATUS_KEY +from .const import DOMAIN + +OUTDOOR_TEMPERATURE_STATUS_KEY = "outdoor_temperature" +OUTDOOR_HUMIDITY_STATUS_KEY = "outdoor_humidity" +CURRENT_TEMPERATURE_STATUS_KEY = "current_temperature" +CURRENT_HUMIDITY_STATUS_KEY = "current_humidity" def _get_temperature_sensor_unit(device: Device) -> str: @@ -48,21 +53,35 @@ class HoneywellSensorEntityDescription( SENSOR_TYPES: tuple[HoneywellSensorEntityDescription, ...] = ( HoneywellSensorEntityDescription( - key=TEMPERATURE_STATUS_KEY, - translation_key="outdoor_temperature", + key=OUTDOOR_TEMPERATURE_STATUS_KEY, + translation_key=OUTDOOR_TEMPERATURE_STATUS_KEY, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda device: device.outdoor_temperature, unit_fn=_get_temperature_sensor_unit, ), HoneywellSensorEntityDescription( - key=HUMIDITY_STATUS_KEY, - translation_key="outdoor_humidity", + key=OUTDOOR_HUMIDITY_STATUS_KEY, + translation_key=OUTDOOR_HUMIDITY_STATUS_KEY, device_class=SensorDeviceClass.HUMIDITY, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda device: device.outdoor_humidity, unit_fn=lambda device: PERCENTAGE, ), + HoneywellSensorEntityDescription( + key=CURRENT_TEMPERATURE_STATUS_KEY, + device_class=SensorDeviceClass.TEMPERATURE, + state_class=SensorStateClass.MEASUREMENT, + value_fn=lambda device: device.current_temperature, + unit_fn=_get_temperature_sensor_unit, + ), + HoneywellSensorEntityDescription( + key=CURRENT_HUMIDITY_STATUS_KEY, + device_class=SensorDeviceClass.HUMIDITY, + state_class=SensorStateClass.MEASUREMENT, + value_fn=lambda device: device.current_humidity, + unit_fn=lambda device: PERCENTAGE, + ), ) @@ -89,7 +108,7 @@ class HoneywellSensor(SensorEntity): entity_description: HoneywellSensorEntityDescription _attr_has_entity_name = True - def __init__(self, device, description): + def __init__(self, device, description) -> None: """Initialize the outdoor temperature sensor.""" self._device = device self.entity_description = description diff --git a/tests/components/honeywell/conftest.py b/tests/components/honeywell/conftest.py index bedd42909443f1..8406d76803a330 100644 --- a/tests/components/honeywell/conftest.py +++ b/tests/components/honeywell/conftest.py @@ -121,7 +121,7 @@ def device_with_outdoor_sensor(): "hasFan": False, } mock_device.system_mode = "off" - mock_device.name = "device1" + mock_device.name = "device3" mock_device.current_temperature = CURRENTTEMPERATURE mock_device.mac_address = "macaddress1" mock_device.temperature_unit = "C" diff --git a/tests/components/honeywell/test_climate.py b/tests/components/honeywell/test_climate.py index 4d6989d79e8829..db390ddc2c3756 100644 --- a/tests/components/honeywell/test_climate.py +++ b/tests/components/honeywell/test_climate.py @@ -54,7 +54,9 @@ async def test_no_thermostat_options( """Test the setup of the climate entities when there are no additional options available.""" device._data = {} await init_integration(hass, config_entry) - assert len(hass.states.async_all()) == 1 + assert hass.states.get("climate.device1") + assert hass.states.get("sensor.device1_temperature") + assert hass.states.get("sensor.device1_humidity") async def test_static_attributes( diff --git a/tests/components/honeywell/test_init.py b/tests/components/honeywell/test_init.py index 36c94c83f318ea..f7629fa958e887 100644 --- a/tests/components/honeywell/test_init.py +++ b/tests/components/honeywell/test_init.py @@ -27,7 +27,9 @@ async def test_setup_entry(hass: HomeAssistant, config_entry: MockConfigEntry) - await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() assert config_entry.state is ConfigEntryState.LOADED - assert hass.states.async_entity_ids_count() == 1 + assert ( + hass.states.async_entity_ids_count() == 3 + ) # 1 climate entity; 2 sensor entities async def test_setup_multiple_thermostats( @@ -39,7 +41,9 @@ async def test_setup_multiple_thermostats( await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() assert config_entry.state is ConfigEntryState.LOADED - assert hass.states.async_entity_ids_count() == 2 + assert ( + hass.states.async_entity_ids_count() == 6 + ) # 2 climate entities; 4 sensor entities async def test_setup_multiple_thermostats_with_same_deviceid( @@ -58,7 +62,9 @@ async def test_setup_multiple_thermostats_with_same_deviceid( await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() assert config_entry.state is ConfigEntryState.LOADED - assert hass.states.async_entity_ids_count() == 1 + assert ( + hass.states.async_entity_ids_count() == 3 + ) # 1 climate entity; 2 sensor entities assert "Platform honeywell does not generate unique IDs" not in caplog.text diff --git a/tests/components/honeywell/test_sensor.py b/tests/components/honeywell/test_sensor.py index c40c90131a8003..b286132a40f1af 100644 --- a/tests/components/honeywell/test_sensor.py +++ b/tests/components/honeywell/test_sensor.py @@ -26,8 +26,38 @@ async def test_outdoor_sensor( await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - temperature_state = hass.states.get("sensor.device1_outdoor_temperature") - humidity_state = hass.states.get("sensor.device1_outdoor_humidity") + temperature_state = hass.states.get("sensor.device3_outdoor_temperature") + humidity_state = hass.states.get("sensor.device3_outdoor_humidity") + + assert temperature_state + assert humidity_state + assert temperature_state.state == temp + assert humidity_state.state == "25" + + +@pytest.mark.parametrize(("unit", "temp"), [("C", "5"), ("F", "-15")]) +async def test_indoor_sensor( + hass: HomeAssistant, + config_entry: MockConfigEntry, + location: Location, + device: Device, + unit, + temp, +) -> None: + """Test indoor temperature sensor with no outdoor sensors.""" + device.temperature_unit = unit + device.current_temperature = 5 + device.current_humidity = 25 + location.devices_by_id[device.deviceid] = device + config_entry.add_to_hass(hass) + await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() + + assert hass.states.get("sensor.device1_outdoor_temperature") is None + assert hass.states.get("sensor.device1_outdoor_humidity") is None + + temperature_state = hass.states.get("sensor.device1_temperature") + humidity_state = hass.states.get("sensor.device1_humidity") assert temperature_state assert humidity_state