Add Select platform to Advantage Air (#54747)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Brett Adams 2021-10-27 11:58:14 +10:00 committed by GitHub
parent e75e40f26e
commit b57b2e0243
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 117 additions and 3 deletions

View File

@ -12,7 +12,7 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda
from .const import ADVANTAGE_AIR_RETRY, DOMAIN
ADVANTAGE_AIR_SYNC_INTERVAL = 15
PLATFORMS = ["climate", "cover", "binary_sensor", "sensor", "switch"]
PLATFORMS = ["binary_sensor", "climate", "cover", "select", "sensor", "switch"]
_LOGGER = logging.getLogger(__name__)

View File

@ -0,0 +1,53 @@
"""Select platform for Advantage Air integration."""
from homeassistant.components.select import SelectEntity
from .const import DOMAIN as ADVANTAGE_AIR_DOMAIN
from .entity import AdvantageAirEntity
ADVANTAGE_AIR_INACTIVE = "Inactive"
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up AdvantageAir toggle platform."""
instance = hass.data[ADVANTAGE_AIR_DOMAIN][config_entry.entry_id]
entities = []
for ac_key in instance["coordinator"].data["aircons"]:
entities.append(AdvantageAirMyZone(instance, ac_key))
async_add_entities(entities)
class AdvantageAirMyZone(AdvantageAirEntity, SelectEntity):
"""Representation of Advantage Air MyZone control."""
_attr_icon = "mdi:home-thermometer"
_attr_options = [ADVANTAGE_AIR_INACTIVE]
_number_to_name = {0: ADVANTAGE_AIR_INACTIVE}
_name_to_number = {ADVANTAGE_AIR_INACTIVE: 0}
def __init__(self, instance, ac_key):
"""Initialize an Advantage Air MyZone control."""
super().__init__(instance, ac_key)
self._attr_name = f'{self._ac["name"]} MyZone'
self._attr_unique_id = (
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-myzone'
)
for zone in instance["coordinator"].data["aircons"][ac_key]["zones"].values():
if zone["type"] > 0:
self._name_to_number[zone["name"]] = zone["number"]
self._number_to_name[zone["number"]] = zone["name"]
self._attr_options.append(zone["name"])
@property
def current_option(self):
"""Return the fresh air status."""
return self._number_to_name[self._ac["myZone"]]
async def async_select_option(self, option):
"""Set the MyZone."""
await self.async_change(
{self.ac_key: {"info": {"myZone": self._name_to_number[option]}}}
)

View File

@ -0,0 +1,61 @@
"""Test the Advantage Air Select Platform."""
from json import loads
from homeassistant.components.select.const import (
ATTR_OPTION,
DOMAIN as SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
)
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.helpers import entity_registry as er
from tests.components.advantage_air import (
TEST_SET_RESPONSE,
TEST_SET_URL,
TEST_SYSTEM_DATA,
TEST_SYSTEM_URL,
add_mock_config,
)
async def test_select_async_setup_entry(hass, aioclient_mock):
"""Test climate setup without sensors."""
aioclient_mock.get(
TEST_SYSTEM_URL,
text=TEST_SYSTEM_DATA,
)
aioclient_mock.get(
TEST_SET_URL,
text=TEST_SET_RESPONSE,
)
await add_mock_config(hass)
registry = er.async_get(hass)
assert len(aioclient_mock.mock_calls) == 1
# Test Select Entity
entity_id = "select.ac_one_myzone"
state = hass.states.get(entity_id)
assert state
assert state.state == "Zone open with Sensor"
entry = registry.async_get(entity_id)
assert entry
assert entry.unique_id == "uniqueid-ac1-myzone"
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{ATTR_ENTITY_ID: entity_id, ATTR_OPTION: "Zone 3"},
blocking=True,
)
assert len(aioclient_mock.mock_calls) == 3
assert aioclient_mock.mock_calls[-2][0] == "GET"
assert aioclient_mock.mock_calls[-2][1].path == "/setAircon"
data = loads(aioclient_mock.mock_calls[-2][1].query["json"])
assert data["ac1"]["info"]["myZone"] == 3
assert aioclient_mock.mock_calls[-1][0] == "GET"
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"

View File

@ -83,7 +83,7 @@
"motion": 5,
"motionConfig": 1,
"name": "Zone 5",
"number": 1,
"number": 5,
"rssi": 100,
"setTemp": 24,
"state": "close",
@ -104,7 +104,7 @@
"myAutoModeCurrentSetMode": "cool",
"myAutoModeEnabled": true,
"myAutoModeIsRunning": true,
"myZone": 1,
"myZone": 0,
"name": "AC Two",
"setTemp": 24,
"state": "off"