Migrate Advantage Air to new entity naming style (#74940)

pull/74993/head
Brett Adams 2022-07-11 14:03:48 +10:00 committed by GitHub
parent abb11009b4
commit 7a729aed54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 36 additions and 34 deletions

View File

@ -27,7 +27,7 @@ async def async_setup_entry(
entities: list[BinarySensorEntity] = [] entities: list[BinarySensorEntity] = []
for ac_key, ac_device in instance["coordinator"].data["aircons"].items(): for ac_key, ac_device in instance["coordinator"].data["aircons"].items():
entities.append(AdvantageAirZoneFilter(instance, ac_key)) entities.append(AdvantageAirFilter(instance, ac_key))
for zone_key, zone in ac_device["zones"].items(): for zone_key, zone in ac_device["zones"].items():
# Only add motion sensor when motion is enabled # Only add motion sensor when motion is enabled
if zone["motionConfig"] >= 2: if zone["motionConfig"] >= 2:
@ -38,7 +38,7 @@ async def async_setup_entry(
async_add_entities(entities) async_add_entities(entities)
class AdvantageAirZoneFilter(AdvantageAirEntity, BinarySensorEntity): class AdvantageAirFilter(AdvantageAirEntity, BinarySensorEntity):
"""Advantage Air Filter.""" """Advantage Air Filter."""
_attr_device_class = BinarySensorDeviceClass.PROBLEM _attr_device_class = BinarySensorDeviceClass.PROBLEM
@ -47,7 +47,7 @@ class AdvantageAirZoneFilter(AdvantageAirEntity, BinarySensorEntity):
def __init__(self, instance, ac_key): def __init__(self, instance, ac_key):
"""Initialize an Advantage Air Filter.""" """Initialize an Advantage Air Filter."""
super().__init__(instance, ac_key) super().__init__(instance, ac_key)
self._attr_name = f'{self._ac["name"]} Filter' self._attr_name = f'{self._ac["name"]} filter'
self._attr_unique_id = ( self._attr_unique_id = (
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-filter' f'{self.coordinator.data["system"]["rid"]}-{ac_key}-filter'
) )
@ -66,7 +66,7 @@ class AdvantageAirZoneMotion(AdvantageAirEntity, BinarySensorEntity):
def __init__(self, instance, ac_key, zone_key): def __init__(self, instance, ac_key, zone_key):
"""Initialize an Advantage Air Zone Motion.""" """Initialize an Advantage Air Zone Motion."""
super().__init__(instance, ac_key, zone_key) super().__init__(instance, ac_key, zone_key)
self._attr_name = f'{self._zone["name"]} Motion' self._attr_name = f'{self._zone["name"]} motion'
self._attr_unique_id = ( self._attr_unique_id = (
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}-motion' f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}-motion'
) )
@ -86,7 +86,7 @@ class AdvantageAirZoneMyZone(AdvantageAirEntity, BinarySensorEntity):
def __init__(self, instance, ac_key, zone_key): def __init__(self, instance, ac_key, zone_key):
"""Initialize an Advantage Air Zone MyZone.""" """Initialize an Advantage Air Zone MyZone."""
super().__init__(instance, ac_key, zone_key) super().__init__(instance, ac_key, zone_key)
self._attr_name = f'{self._zone["name"]} MyZone' self._attr_name = f'{self._zone["name"]} myZone'
self._attr_unique_id = ( self._attr_unique_id = (
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}-myzone' f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}-myzone'
) )

View File

@ -52,7 +52,7 @@ class AdvantageAirZoneVent(AdvantageAirEntity, CoverEntity):
def __init__(self, instance, ac_key, zone_key): def __init__(self, instance, ac_key, zone_key):
"""Initialize an Advantage Air Cover Class.""" """Initialize an Advantage Air Cover Class."""
super().__init__(instance, ac_key, zone_key) super().__init__(instance, ac_key, zone_key)
self._attr_name = f'{self._zone["name"]}' self._attr_name = self._zone["name"]
self._attr_unique_id = ( self._attr_unique_id = (
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}' f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}'
) )

View File

@ -9,6 +9,8 @@ from .const import DOMAIN
class AdvantageAirEntity(CoordinatorEntity): class AdvantageAirEntity(CoordinatorEntity):
"""Parent class for Advantage Air Entities.""" """Parent class for Advantage Air Entities."""
_attr_has_entity_name = True
def __init__(self, instance, ac_key, zone_key=None): def __init__(self, instance, ac_key, zone_key=None):
"""Initialize common aspects of an Advantage Air sensor.""" """Initialize common aspects of an Advantage Air sensor."""
super().__init__(instance["coordinator"]) super().__init__(instance["coordinator"])

View File

@ -36,7 +36,7 @@ class AdvantageAirMyZone(AdvantageAirEntity, SelectEntity):
def __init__(self, instance, ac_key): def __init__(self, instance, ac_key):
"""Initialize an Advantage Air MyZone control.""" """Initialize an Advantage Air MyZone control."""
super().__init__(instance, ac_key) super().__init__(instance, ac_key)
self._attr_name = f'{self._ac["name"]} MyZone' self._attr_name = f'{self._ac["name"]} myZone'
self._attr_unique_id = ( self._attr_unique_id = (
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-myzone' f'{self.coordinator.data["system"]["rid"]}-{ac_key}-myzone'
) )

View File

@ -67,7 +67,7 @@ class AdvantageAirTimeTo(AdvantageAirEntity, SensorEntity):
super().__init__(instance, ac_key) super().__init__(instance, ac_key)
self.action = action self.action = action
self._time_key = f"countDownTo{action}" self._time_key = f"countDownTo{action}"
self._attr_name = f'{self._ac["name"]} Time To {action}' self._attr_name = f'{self._ac["name"]} time to {action}'
self._attr_unique_id = ( self._attr_unique_id = (
f'{self.coordinator.data["system"]["rid"]}-{self.ac_key}-timeto{action}' f'{self.coordinator.data["system"]["rid"]}-{self.ac_key}-timeto{action}'
) )
@ -100,7 +100,7 @@ class AdvantageAirZoneVent(AdvantageAirEntity, SensorEntity):
def __init__(self, instance, ac_key, zone_key): def __init__(self, instance, ac_key, zone_key):
"""Initialize an Advantage Air Zone Vent Sensor.""" """Initialize an Advantage Air Zone Vent Sensor."""
super().__init__(instance, ac_key, zone_key=zone_key) super().__init__(instance, ac_key, zone_key=zone_key)
self._attr_name = f'{self._zone["name"]} Vent' self._attr_name = f'{self._zone["name"]} vent'
self._attr_unique_id = ( self._attr_unique_id = (
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}-vent' f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}-vent'
) )
@ -130,7 +130,7 @@ class AdvantageAirZoneSignal(AdvantageAirEntity, SensorEntity):
def __init__(self, instance, ac_key, zone_key): def __init__(self, instance, ac_key, zone_key):
"""Initialize an Advantage Air Zone wireless signal sensor.""" """Initialize an Advantage Air Zone wireless signal sensor."""
super().__init__(instance, ac_key, zone_key) super().__init__(instance, ac_key, zone_key)
self._attr_name = f'{self._zone["name"]} Signal' self._attr_name = f'{self._zone["name"]} signal'
self._attr_unique_id = ( self._attr_unique_id = (
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}-signal' f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}-signal'
) )
@ -166,7 +166,7 @@ class AdvantageAirZoneTemp(AdvantageAirEntity, SensorEntity):
def __init__(self, instance, ac_key, zone_key): def __init__(self, instance, ac_key, zone_key):
"""Initialize an Advantage Air Zone Temp Sensor.""" """Initialize an Advantage Air Zone Temp Sensor."""
super().__init__(instance, ac_key, zone_key) super().__init__(instance, ac_key, zone_key)
self._attr_name = f'{self._zone["name"]} Temperature' self._attr_name = f'{self._zone["name"]} temperature'
self._attr_unique_id = ( self._attr_unique_id = (
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}-temp' f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}-temp'
) )

View File

@ -34,7 +34,7 @@ async def test_binary_sensor_async_setup_entry(hass, aioclient_mock):
assert len(aioclient_mock.mock_calls) == 1 assert len(aioclient_mock.mock_calls) == 1
# Test First Air Filter # Test First Air Filter
entity_id = "binary_sensor.ac_one_filter" entity_id = "binary_sensor.testname_ac_one_filter"
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert state assert state
assert state.state == STATE_OFF assert state.state == STATE_OFF
@ -44,7 +44,7 @@ async def test_binary_sensor_async_setup_entry(hass, aioclient_mock):
assert entry.unique_id == "uniqueid-ac1-filter" assert entry.unique_id == "uniqueid-ac1-filter"
# Test Second Air Filter # Test Second Air Filter
entity_id = "binary_sensor.ac_two_filter" entity_id = "binary_sensor.testname_ac_two_filter"
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert state assert state
assert state.state == STATE_ON assert state.state == STATE_ON
@ -54,7 +54,7 @@ async def test_binary_sensor_async_setup_entry(hass, aioclient_mock):
assert entry.unique_id == "uniqueid-ac2-filter" assert entry.unique_id == "uniqueid-ac2-filter"
# Test First Motion Sensor # Test First Motion Sensor
entity_id = "binary_sensor.zone_open_with_sensor_motion" entity_id = "binary_sensor.testname_zone_open_with_sensor_motion"
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert state assert state
assert state.state == STATE_ON assert state.state == STATE_ON
@ -64,7 +64,7 @@ async def test_binary_sensor_async_setup_entry(hass, aioclient_mock):
assert entry.unique_id == "uniqueid-ac1-z01-motion" assert entry.unique_id == "uniqueid-ac1-z01-motion"
# Test Second Motion Sensor # Test Second Motion Sensor
entity_id = "binary_sensor.zone_closed_with_sensor_motion" entity_id = "binary_sensor.testname_zone_closed_with_sensor_motion"
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert state assert state
assert state.state == STATE_OFF assert state.state == STATE_OFF
@ -74,7 +74,7 @@ async def test_binary_sensor_async_setup_entry(hass, aioclient_mock):
assert entry.unique_id == "uniqueid-ac1-z02-motion" assert entry.unique_id == "uniqueid-ac1-z02-motion"
# Test First MyZone Sensor (disabled by default) # Test First MyZone Sensor (disabled by default)
entity_id = "binary_sensor.zone_open_with_sensor_myzone" entity_id = "binary_sensor.testname_zone_open_with_sensor_myzone"
assert not hass.states.get(entity_id) assert not hass.states.get(entity_id)
@ -96,7 +96,7 @@ async def test_binary_sensor_async_setup_entry(hass, aioclient_mock):
assert entry.unique_id == "uniqueid-ac1-z01-myzone" assert entry.unique_id == "uniqueid-ac1-z01-myzone"
# Test Second Motion Sensor (disabled by default) # Test Second Motion Sensor (disabled by default)
entity_id = "binary_sensor.zone_closed_with_sensor_myzone" entity_id = "binary_sensor.testname_zone_closed_with_sensor_myzone"
assert not hass.states.get(entity_id) assert not hass.states.get(entity_id)

View File

@ -51,7 +51,7 @@ async def test_climate_async_setup_entry(hass, aioclient_mock):
assert len(aioclient_mock.mock_calls) == 1 assert len(aioclient_mock.mock_calls) == 1
# Test Main Climate Entity # Test Main Climate Entity
entity_id = "climate.ac_one" entity_id = "climate.testname_ac_one"
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert state assert state
assert state.state == HVACMode.FAN_ONLY assert state.state == HVACMode.FAN_ONLY
@ -122,7 +122,7 @@ async def test_climate_async_setup_entry(hass, aioclient_mock):
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData" assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
# Test Climate Zone Entity # Test Climate Zone Entity
entity_id = "climate.zone_open_with_sensor" entity_id = "climate.testname_zone_open_with_sensor"
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert state assert state
assert state.attributes.get("min_temp") == 16 assert state.attributes.get("min_temp") == 16
@ -204,7 +204,7 @@ async def test_climate_async_failed_update(hass, aioclient_mock):
await hass.services.async_call( await hass.services.async_call(
CLIMATE_DOMAIN, CLIMATE_DOMAIN,
SERVICE_SET_TEMPERATURE, SERVICE_SET_TEMPERATURE,
{ATTR_ENTITY_ID: ["climate.ac_one"], ATTR_TEMPERATURE: 25}, {ATTR_ENTITY_ID: ["climate.testname_ac_one"], ATTR_TEMPERATURE: 25},
blocking=True, blocking=True,
) )
assert len(aioclient_mock.mock_calls) == 2 assert len(aioclient_mock.mock_calls) == 2

View File

@ -45,7 +45,7 @@ async def test_cover_async_setup_entry(hass, aioclient_mock):
assert len(aioclient_mock.mock_calls) == 1 assert len(aioclient_mock.mock_calls) == 1
# Test Cover Zone Entity # Test Cover Zone Entity
entity_id = "cover.zone_open_without_sensor" entity_id = "cover.testname_zone_open_without_sensor"
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert state assert state
assert state.state == STATE_OPEN assert state.state == STATE_OPEN
@ -119,8 +119,8 @@ async def test_cover_async_setup_entry(hass, aioclient_mock):
SERVICE_CLOSE_COVER, SERVICE_CLOSE_COVER,
{ {
ATTR_ENTITY_ID: [ ATTR_ENTITY_ID: [
"cover.zone_open_without_sensor", "cover.testname_zone_open_without_sensor",
"cover.zone_closed_without_sensor", "cover.testname_zone_closed_without_sensor",
] ]
}, },
blocking=True, blocking=True,
@ -134,8 +134,8 @@ async def test_cover_async_setup_entry(hass, aioclient_mock):
SERVICE_OPEN_COVER, SERVICE_OPEN_COVER,
{ {
ATTR_ENTITY_ID: [ ATTR_ENTITY_ID: [
"cover.zone_open_without_sensor", "cover.testname_zone_open_without_sensor",
"cover.zone_closed_without_sensor", "cover.testname_zone_closed_without_sensor",
] ]
}, },
blocking=True, blocking=True,

View File

@ -37,7 +37,7 @@ async def test_select_async_setup_entry(hass, aioclient_mock):
assert len(aioclient_mock.mock_calls) == 1 assert len(aioclient_mock.mock_calls) == 1
# Test Select Entity # Test Select Entity
entity_id = "select.ac_one_myzone" entity_id = "select.testname_ac_one_myzone"
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert state assert state
assert state.state == "Zone open with Sensor" assert state.state == "Zone open with Sensor"

View File

@ -41,7 +41,7 @@ async def test_sensor_platform(hass, aioclient_mock):
assert len(aioclient_mock.mock_calls) == 1 assert len(aioclient_mock.mock_calls) == 1
# Test First TimeToOn Sensor # Test First TimeToOn Sensor
entity_id = "sensor.ac_one_time_to_on" entity_id = "sensor.testname_ac_one_time_to_on"
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert state assert state
assert int(state.state) == 0 assert int(state.state) == 0
@ -66,7 +66,7 @@ async def test_sensor_platform(hass, aioclient_mock):
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData" assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
# Test First TimeToOff Sensor # Test First TimeToOff Sensor
entity_id = "sensor.ac_one_time_to_off" entity_id = "sensor.testname_ac_one_time_to_off"
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert state assert state
assert int(state.state) == 10 assert int(state.state) == 10
@ -91,7 +91,7 @@ async def test_sensor_platform(hass, aioclient_mock):
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData" assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
# Test First Zone Vent Sensor # Test First Zone Vent Sensor
entity_id = "sensor.zone_open_with_sensor_vent" entity_id = "sensor.testname_zone_open_with_sensor_vent"
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert state assert state
assert int(state.state) == 100 assert int(state.state) == 100
@ -101,7 +101,7 @@ async def test_sensor_platform(hass, aioclient_mock):
assert entry.unique_id == "uniqueid-ac1-z01-vent" assert entry.unique_id == "uniqueid-ac1-z01-vent"
# Test Second Zone Vent Sensor # Test Second Zone Vent Sensor
entity_id = "sensor.zone_closed_with_sensor_vent" entity_id = "sensor.testname_zone_closed_with_sensor_vent"
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert state assert state
assert int(state.state) == 0 assert int(state.state) == 0
@ -111,7 +111,7 @@ async def test_sensor_platform(hass, aioclient_mock):
assert entry.unique_id == "uniqueid-ac1-z02-vent" assert entry.unique_id == "uniqueid-ac1-z02-vent"
# Test First Zone Signal Sensor # Test First Zone Signal Sensor
entity_id = "sensor.zone_open_with_sensor_signal" entity_id = "sensor.testname_zone_open_with_sensor_signal"
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert state assert state
assert int(state.state) == 40 assert int(state.state) == 40
@ -121,7 +121,7 @@ async def test_sensor_platform(hass, aioclient_mock):
assert entry.unique_id == "uniqueid-ac1-z01-signal" assert entry.unique_id == "uniqueid-ac1-z01-signal"
# Test Second Zone Signal Sensor # Test Second Zone Signal Sensor
entity_id = "sensor.zone_closed_with_sensor_signal" entity_id = "sensor.testname_zone_closed_with_sensor_signal"
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert state assert state
assert int(state.state) == 10 assert int(state.state) == 10
@ -131,7 +131,7 @@ async def test_sensor_platform(hass, aioclient_mock):
assert entry.unique_id == "uniqueid-ac1-z02-signal" assert entry.unique_id == "uniqueid-ac1-z02-signal"
# Test First Zone Temp Sensor (disabled by default) # Test First Zone Temp Sensor (disabled by default)
entity_id = "sensor.zone_open_with_sensor_temperature" entity_id = "sensor.testname_zone_open_with_sensor_temperature"
assert not hass.states.get(entity_id) assert not hass.states.get(entity_id)

View File

@ -41,7 +41,7 @@ async def test_cover_async_setup_entry(hass, aioclient_mock):
assert len(aioclient_mock.mock_calls) == 1 assert len(aioclient_mock.mock_calls) == 1
# Test Switch Entity # Test Switch Entity
entity_id = "switch.ac_one_fresh_air" entity_id = "switch.testname_ac_one_fresh_air"
state = hass.states.get(entity_id) state = hass.states.get(entity_id)
assert state assert state
assert state.state == STATE_OFF assert state.state == STATE_OFF