Add indoor sensors to Honeywell integration (#98609)
Co-authored-by: Robert Resch <robert@resch.dev> Co-authored-by: G Johansson <goran.johansson@shiftit.se>pull/99215/head
parent
a6788208fe
commit
f1378bba8e
|
@ -9,7 +9,4 @@ DEFAULT_COOL_AWAY_TEMPERATURE = 88
|
|||
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__)
|
||||
|
|
|
@ -21,7 +21,12 @@ 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 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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue