Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add indoor sensors to Honeywell integration #98609

Merged
merged 12 commits into from
Aug 28, 2023
7 changes: 4 additions & 3 deletions homeassistant/components/honeywell/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
DEFAULT_HEAT_AWAY_TEMPERATURE = 61
CONF_DEV_ID = "thermostat"
CONF_LOC_ID = "location"
jakecolman marked this conversation as resolved.
Show resolved Hide resolved
TEMPERATURE_STATUS_KEY = "outdoor_temperature"
HUMIDITY_STATUS_KEY = "outdoor_humidity"

OUTDOOR_TEMPERATURE_STATUS_KEY = "outdoor_temperature"
OUTDOOR_HUMIDITY_STATUS_KEY = "outdoor_humidity"
CURRENT_TEMPERATURE_STATUS_KEY = "current_temperature"
CURRENT_HUMIDITY_STATUS_KEY = "current_humidity"
jakecolman marked this conversation as resolved.
Show resolved Hide resolved
_LOGGER = logging.getLogger(__name__)
31 changes: 26 additions & 5 deletions homeassistant/components/honeywell/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType

from . import HoneywellData
from .const import DOMAIN, HUMIDITY_STATUS_KEY, TEMPERATURE_STATUS_KEY
from .const import (
CURRENT_HUMIDITY_STATUS_KEY,
CURRENT_TEMPERATURE_STATUS_KEY,
DOMAIN,
OUTDOOR_HUMIDITY_STATUS_KEY,
OUTDOOR_TEMPERATURE_STATUS_KEY,
)


def _get_temperature_sensor_unit(device: Device) -> str:
Expand All @@ -48,21 +53,37 @@

SENSOR_TYPES: tuple[HoneywellSensorEntityDescription, ...] = (
HoneywellSensorEntityDescription(
key=TEMPERATURE_STATUS_KEY,
key=OUTDOOR_TEMPERATURE_STATUS_KEY,
translation_key="outdoor_temperature",
jakecolman marked this conversation as resolved.
Show resolved Hide resolved
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,
key=OUTDOOR_HUMIDITY_STATUS_KEY,
translation_key="outdoor_humidity",
jakecolman marked this conversation as resolved.
Show resolved Hide resolved
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,
translation_key="current_temperature",
jakecolman marked this conversation as resolved.
Show resolved Hide resolved
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,
translation_key="current_humidity",
jakecolman marked this conversation as resolved.
Show resolved Hide resolved
device_class=SensorDeviceClass.HUMIDITY,
state_class=SensorStateClass.MEASUREMENT,
value_fn=lambda device: device.current_humidity,
unit_fn=lambda device: PERCENTAGE,
),
)


Expand All @@ -72,7 +93,7 @@
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the Honeywell thermostat."""
data: HoneywellData = hass.data[DOMAIN][config_entry.entry_id]

Check failure on line 96 in homeassistant/components/honeywell/sensor.py

View workflow job for this annotation

GitHub Actions / Check ruff

F821 Undefined name `HoneywellData`

Check failure on line 96 in homeassistant/components/honeywell/sensor.py

View workflow job for this annotation

GitHub Actions / Check mypy

Name "HoneywellData" is not defined [name-defined]
sensors = []

for device in data.devices.values():
Expand All @@ -89,7 +110,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion tests/components/honeywell/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion tests/components/honeywell/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 9 additions & 3 deletions tests/components/honeywell/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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


Expand Down
34 changes: 32 additions & 2 deletions tests/components/honeywell/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down