1
mirror of https://github.com/home-assistant/core synced 2024-09-03 08:14:07 +02:00

Small fixes and cleanups to legacy nexia code (#72176)

This commit is contained in:
J. Nick Koston 2022-05-19 11:50:54 -05:00 committed by GitHub
parent 0422d7f256
commit 1c4c0f1eb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 60 additions and 110 deletions

View File

@ -40,7 +40,6 @@ from .const import (
ATTR_DEHUMIDIFY_SETPOINT,
ATTR_HUMIDIFY_SETPOINT,
ATTR_RUN_MODE,
ATTR_ZONE_STATUS,
DOMAIN,
)
from .coordinator import NexiaDataUpdateCoordinator
@ -344,31 +343,26 @@ class NexiaZone(NexiaThermostatZoneEntity, ClimateEntity):
self._signal_zone_update()
@property
def is_aux_heat(self):
def is_aux_heat(self) -> bool:
"""Emergency heat state."""
return self._thermostat.is_emergency_heat_active()
@property
def extra_state_attributes(self):
def extra_state_attributes(self) -> dict[str, str] | None:
"""Return the device specific state attributes."""
data = super().extra_state_attributes
data[ATTR_ZONE_STATUS] = self._zone.get_status()
if not self._has_relative_humidity:
return data
return None
attrs = {}
if self._has_dehumidify_support:
dehumdify_setpoint = percent_conv(
self._thermostat.get_dehumidify_setpoint()
)
data[ATTR_DEHUMIDIFY_SETPOINT] = dehumdify_setpoint
attrs[ATTR_DEHUMIDIFY_SETPOINT] = dehumdify_setpoint
if self._has_humidify_support:
humdify_setpoint = percent_conv(self._thermostat.get_humidify_setpoint())
data[ATTR_HUMIDIFY_SETPOINT] = humdify_setpoint
return data
attrs[ATTR_HUMIDIFY_SETPOINT] = humdify_setpoint
return attrs
async def async_set_preset_mode(self, preset_mode: str):
"""Set the preset mode."""
@ -376,23 +370,23 @@ class NexiaZone(NexiaThermostatZoneEntity, ClimateEntity):
self._signal_zone_update()
async def async_turn_aux_heat_off(self):
"""Turn. Aux Heat off."""
"""Turn Aux Heat off."""
await self._thermostat.set_emergency_heat(False)
self._signal_thermostat_update()
async def async_turn_aux_heat_on(self):
"""Turn. Aux Heat on."""
"""Turn Aux Heat on."""
self._thermostat.set_emergency_heat(True)
self._signal_thermostat_update()
async def async_turn_off(self):
"""Turn. off the zone."""
await self.set_hvac_mode(OPERATION_MODE_OFF)
"""Turn off the zone."""
await self.async_set_hvac_mode(OPERATION_MODE_OFF)
self._signal_zone_update()
async def async_turn_on(self):
"""Turn. on the zone."""
await self.set_hvac_mode(OPERATION_MODE_AUTO)
"""Turn on the zone."""
await self.async_set_hvac_mode(OPERATION_MODE_AUTO)
self._signal_zone_update()
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:

View File

@ -9,17 +9,11 @@ PLATFORMS = [
Platform.SWITCH,
]
ATTRIBUTION = "Data provided by mynexia.com"
NOTIFICATION_ID = "nexia_notification"
NOTIFICATION_TITLE = "Nexia Setup"
ATTRIBUTION = "Data provided by Trane Technologies"
CONF_BRAND = "brand"
NEXIA_SCAN_INTERVAL = "scan_interval"
DOMAIN = "nexia"
DEFAULT_ENTITY_NAMESPACE = "nexia"
ATTR_DESCRIPTION = "description"
@ -27,7 +21,6 @@ ATTR_AIRCLEANER_MODE = "aircleaner_mode"
ATTR_RUN_MODE = "run_mode"
ATTR_ZONE_STATUS = "zone_status"
ATTR_HUMIDIFY_SETPOINT = "humidify_setpoint"
ATTR_DEHUMIDIFY_SETPOINT = "dehumidify_setpoint"

View File

@ -1,4 +1,4 @@
"""Component to embed TP-Link smart home devices."""
"""Component to embed nexia devices."""
from __future__ import annotations
from datetime import timedelta

View File

@ -1,8 +1,14 @@
"""The nexia integration base entity."""
from nexia.thermostat import NexiaThermostat
from nexia.zone import NexiaThermostatZone
from homeassistant.const import ATTR_ATTRIBUTION
from homeassistant.const import (
ATTR_IDENTIFIERS,
ATTR_NAME,
ATTR_SUGGESTED_AREA,
ATTR_VIA_DEVICE,
)
from homeassistant.helpers.dispatcher import (
async_dispatcher_connect,
async_dispatcher_send,
@ -20,33 +26,18 @@ from .const import (
from .coordinator import NexiaDataUpdateCoordinator
class NexiaEntity(CoordinatorEntity):
class NexiaEntity(CoordinatorEntity[NexiaDataUpdateCoordinator]):
"""Base class for nexia entities."""
_attr_attribution = ATTRIBUTION
def __init__(
self, coordinator: NexiaDataUpdateCoordinator, name: str, unique_id: str
) -> None:
"""Initialize the entity."""
super().__init__(coordinator)
self._unique_id = unique_id
self._name = name
@property
def unique_id(self):
"""Return the unique id."""
return self._unique_id
@property
def name(self):
"""Return the name."""
return self._name
@property
def extra_state_attributes(self):
"""Return the device specific state attributes."""
return {
ATTR_ATTRIBUTION: ATTRIBUTION,
}
self._attr_unique_id = unique_id
self._attr_name = name
class NexiaThermostatEntity(NexiaEntity):
@ -56,12 +47,7 @@ class NexiaThermostatEntity(NexiaEntity):
"""Initialize the entity."""
super().__init__(coordinator, name, unique_id)
self._thermostat: NexiaThermostat = thermostat
@property
def device_info(self) -> DeviceInfo:
"""Return the device_info of the device."""
assert isinstance(self.coordinator, NexiaDataUpdateCoordinator)
return DeviceInfo(
self._attr_device_info = DeviceInfo(
configuration_url=self.coordinator.nexia_home.root_url,
identifiers={(DOMAIN, self._thermostat.thermostat_id)},
manufacturer=MANUFACTURER,
@ -102,21 +88,13 @@ class NexiaThermostatZoneEntity(NexiaThermostatEntity):
"""Initialize the entity."""
super().__init__(coordinator, zone.thermostat, name, unique_id)
self._zone: NexiaThermostatZone = zone
@property
def device_info(self):
"""Return the device_info of the device."""
data = super().device_info
zone_name = self._zone.get_name()
data.update(
{
"identifiers": {(DOMAIN, self._zone.zone_id)},
"name": zone_name,
"suggested_area": zone_name,
"via_device": (DOMAIN, self._zone.thermostat.thermostat_id),
}
)
return data
self._attr_device_info |= {
ATTR_IDENTIFIERS: {(DOMAIN, self._zone.zone_id)},
ATTR_NAME: zone_name,
ATTR_SUGGESTED_AREA: zone_name,
ATTR_VIA_DEVICE: (DOMAIN, self._zone.thermostat.thermostat_id),
}
async def async_added_to_hass(self):
"""Listen for signals for services."""

View File

@ -24,21 +24,19 @@ async def async_setup_entry(
"""Set up automations for a Nexia device."""
coordinator: NexiaDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
nexia_home = coordinator.nexia_home
entities = []
# Automation switches
for automation_id in nexia_home.get_automation_ids():
automation = nexia_home.get_automation_by_id(automation_id)
entities.append(NexiaAutomationScene(coordinator, automation))
async_add_entities(entities)
async_add_entities(
NexiaAutomationScene(
coordinator, nexia_home.get_automation_by_id(automation_id)
)
for automation_id in nexia_home.get_automation_ids()
)
class NexiaAutomationScene(NexiaEntity, Scene):
"""Provides Nexia automation support."""
_attr_icon = "mdi:script-text-outline"
def __init__(
self, coordinator: NexiaDataUpdateCoordinator, automation: NexiaAutomation
) -> None:
@ -48,19 +46,8 @@ class NexiaAutomationScene(NexiaEntity, Scene):
name=automation.name,
unique_id=automation.automation_id,
)
self._automation = automation
@property
def extra_state_attributes(self):
"""Return the scene specific state attributes."""
data = super().extra_state_attributes
data[ATTR_DESCRIPTION] = self._automation.description
return data
@property
def icon(self):
"""Return the icon of the automation scene."""
return "mdi:script-text-outline"
self._automation: NexiaAutomation = automation
self._attr_extra_state_attributes = {ATTR_DESCRIPTION: automation.description}
async def async_activate(self, **kwargs: Any) -> None:
"""Activate an automation scene."""

View File

@ -13,7 +13,7 @@ async def test_create_binary_sensors(hass):
state = hass.states.get("binary_sensor.master_suite_blower_active")
assert state.state == STATE_ON
expected_attributes = {
"attribution": "Data provided by mynexia.com",
"attribution": "Data provided by Trane Technologies",
"friendly_name": "Master Suite Blower Active",
}
# Only test for a subset of attributes in case
@ -25,7 +25,7 @@ async def test_create_binary_sensors(hass):
state = hass.states.get("binary_sensor.downstairs_east_wing_blower_active")
assert state.state == STATE_OFF
expected_attributes = {
"attribution": "Data provided by mynexia.com",
"attribution": "Data provided by Trane Technologies",
"friendly_name": "Downstairs East Wing Blower Active",
}
# Only test for a subset of attributes in case

View File

@ -12,7 +12,7 @@ async def test_climate_zones(hass):
state = hass.states.get("climate.nick_office")
assert state.state == HVACMode.HEAT_COOL
expected_attributes = {
"attribution": "Data provided by mynexia.com",
"attribution": "Data provided by Trane Technologies",
"current_humidity": 52.0,
"current_temperature": 22.8,
"dehumidify_setpoint": 45.0,
@ -33,7 +33,6 @@ async def test_climate_zones(hass):
"target_temp_low": 17.2,
"target_temp_step": 1.0,
"temperature": None,
"zone_status": "Relieving Air",
}
# Only test for a subset of attributes in case
# HA changes the implementation and a new one appears
@ -45,7 +44,7 @@ async def test_climate_zones(hass):
assert state.state == HVACMode.HEAT_COOL
expected_attributes = {
"attribution": "Data provided by mynexia.com",
"attribution": "Data provided by Trane Technologies",
"current_humidity": 36.0,
"current_temperature": 25.0,
"dehumidify_setpoint": 50.0,
@ -66,7 +65,6 @@ async def test_climate_zones(hass):
"target_temp_low": 17.2,
"target_temp_step": 1.0,
"temperature": None,
"zone_status": "Idle",
}
# Only test for a subset of attributes in case

View File

@ -10,7 +10,7 @@ async def test_automation_scenes(hass):
state = hass.states.get("scene.away_short")
expected_attributes = {
"attribution": "Data provided by mynexia.com",
"attribution": "Data provided by Trane Technologies",
"description": "When IFTTT activates the automation Upstairs "
"West Wing will permanently hold the heat to 63.0 "
"and cool to 80.0 AND Downstairs East Wing will "
@ -37,7 +37,7 @@ async def test_automation_scenes(hass):
state = hass.states.get("scene.power_outage")
expected_attributes = {
"attribution": "Data provided by mynexia.com",
"attribution": "Data provided by Trane Technologies",
"description": "When IFTTT activates the automation Upstairs "
"West Wing will permanently hold the heat to 55.0 "
"and cool to 90.0 AND Downstairs East Wing will "
@ -56,7 +56,7 @@ async def test_automation_scenes(hass):
state = hass.states.get("scene.power_restored")
expected_attributes = {
"attribution": "Data provided by mynexia.com",
"attribution": "Data provided by Trane Technologies",
"description": "When IFTTT activates the automation Upstairs "
"West Wing will Run Schedule AND Downstairs East "
"Wing will Run Schedule AND Downstairs West Wing "

View File

@ -14,7 +14,7 @@ async def test_create_sensors(hass):
assert state.state == "23"
expected_attributes = {
"attribution": "Data provided by mynexia.com",
"attribution": "Data provided by Trane Technologies",
"device_class": "temperature",
"friendly_name": "Nick Office Temperature",
"unit_of_measurement": TEMP_CELSIUS,
@ -28,7 +28,7 @@ async def test_create_sensors(hass):
state = hass.states.get("sensor.nick_office_zone_setpoint_status")
assert state.state == "Permanent Hold"
expected_attributes = {
"attribution": "Data provided by mynexia.com",
"attribution": "Data provided by Trane Technologies",
"friendly_name": "Nick Office Zone Setpoint Status",
}
# Only test for a subset of attributes in case
@ -41,7 +41,7 @@ async def test_create_sensors(hass):
assert state.state == "Relieving Air"
expected_attributes = {
"attribution": "Data provided by mynexia.com",
"attribution": "Data provided by Trane Technologies",
"friendly_name": "Nick Office Zone Status",
}
# Only test for a subset of attributes in case
@ -54,7 +54,7 @@ async def test_create_sensors(hass):
assert state.state == "auto"
expected_attributes = {
"attribution": "Data provided by mynexia.com",
"attribution": "Data provided by Trane Technologies",
"friendly_name": "Master Suite Air Cleaner Mode",
}
# Only test for a subset of attributes in case
@ -67,7 +67,7 @@ async def test_create_sensors(hass):
assert state.state == "69.0"
expected_attributes = {
"attribution": "Data provided by mynexia.com",
"attribution": "Data provided by Trane Technologies",
"friendly_name": "Master Suite Current Compressor Speed",
"unit_of_measurement": PERCENTAGE,
}
@ -81,7 +81,7 @@ async def test_create_sensors(hass):
assert state.state == "30.6"
expected_attributes = {
"attribution": "Data provided by mynexia.com",
"attribution": "Data provided by Trane Technologies",
"device_class": "temperature",
"friendly_name": "Master Suite Outdoor Temperature",
"unit_of_measurement": TEMP_CELSIUS,
@ -96,7 +96,7 @@ async def test_create_sensors(hass):
assert state.state == "52.0"
expected_attributes = {
"attribution": "Data provided by mynexia.com",
"attribution": "Data provided by Trane Technologies",
"device_class": "humidity",
"friendly_name": "Master Suite Relative Humidity",
"unit_of_measurement": PERCENTAGE,
@ -111,7 +111,7 @@ async def test_create_sensors(hass):
assert state.state == "69.0"
expected_attributes = {
"attribution": "Data provided by mynexia.com",
"attribution": "Data provided by Trane Technologies",
"friendly_name": "Master Suite Requested Compressor Speed",
"unit_of_measurement": PERCENTAGE,
}
@ -125,7 +125,7 @@ async def test_create_sensors(hass):
assert state.state == "Cooling"
expected_attributes = {
"attribution": "Data provided by mynexia.com",
"attribution": "Data provided by Trane Technologies",
"friendly_name": "Master Suite System Status",
}
# Only test for a subset of attributes in case