Add update platform to Advantage Air (#75391)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
7c27be230c
commit
779e020dc4
5 changed files with 132 additions and 1 deletions
|
@ -20,6 +20,7 @@ PLATFORMS = [
|
|||
Platform.SELECT,
|
||||
Platform.SENSOR,
|
||||
Platform.SWITCH,
|
||||
Platform.UPDATE,
|
||||
Platform.LIGHT,
|
||||
]
|
||||
|
||||
|
|
52
homeassistant/components/advantage_air/update.py
Normal file
52
homeassistant/components/advantage_air/update.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
"""Advantage Air Update platform."""
|
||||
from homeassistant.components.update import UpdateEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN as ADVANTAGE_AIR_DOMAIN
|
||||
from .entity import AdvantageAirEntity
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up AdvantageAir update platform."""
|
||||
|
||||
instance = hass.data[ADVANTAGE_AIR_DOMAIN][config_entry.entry_id]
|
||||
|
||||
async_add_entities([AdvantageAirApp(instance)])
|
||||
|
||||
|
||||
class AdvantageAirApp(AdvantageAirEntity, UpdateEntity):
|
||||
"""Representation of Advantage Air App."""
|
||||
|
||||
_attr_name = "App"
|
||||
|
||||
def __init__(self, instance):
|
||||
"""Initialize the Advantage Air App."""
|
||||
super().__init__(instance)
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={
|
||||
(ADVANTAGE_AIR_DOMAIN, self.coordinator.data["system"]["rid"])
|
||||
},
|
||||
manufacturer="Advantage Air",
|
||||
model=self.coordinator.data["system"]["sysType"],
|
||||
name=self.coordinator.data["system"]["name"],
|
||||
sw_version=self.coordinator.data["system"]["myAppRev"],
|
||||
)
|
||||
|
||||
@property
|
||||
def installed_version(self):
|
||||
"""Return the current app version."""
|
||||
return self.coordinator.data["system"]["myAppRev"]
|
||||
|
||||
@property
|
||||
def latest_version(self):
|
||||
"""Return if there is an update."""
|
||||
if self.coordinator.data["system"]["needsUpdate"]:
|
||||
return "Needs Update"
|
||||
return self.installed_version
|
|
@ -167,9 +167,10 @@
|
|||
"hasThings": false,
|
||||
"hasThingsBOG": false,
|
||||
"hasThingsLight": false,
|
||||
"needsUpdate": false,
|
||||
"name": "testname",
|
||||
"rid": "uniqueid",
|
||||
"sysType": "e-zone",
|
||||
"myAppRev": "testversion"
|
||||
"myAppRev": "1.234"
|
||||
}
|
||||
}
|
||||
|
|
49
tests/components/advantage_air/fixtures/needsUpdate.json
Normal file
49
tests/components/advantage_air/fixtures/needsUpdate.json
Normal file
|
@ -0,0 +1,49 @@
|
|||
{
|
||||
"aircons": {
|
||||
"ac1": {
|
||||
"info": {
|
||||
"climateControlModeIsRunning": false,
|
||||
"countDownToOff": 10,
|
||||
"countDownToOn": 0,
|
||||
"fan": "high",
|
||||
"filterCleanStatus": 0,
|
||||
"freshAirStatus": "off",
|
||||
"mode": "vent",
|
||||
"myZone": 1,
|
||||
"name": "AC One",
|
||||
"setTemp": 24,
|
||||
"state": "on"
|
||||
},
|
||||
"zones": {
|
||||
"z01": {
|
||||
"error": 0,
|
||||
"maxDamper": 100,
|
||||
"measuredTemp": 25,
|
||||
"minDamper": 0,
|
||||
"motion": 20,
|
||||
"motionConfig": 2,
|
||||
"name": "Zone open with Sensor",
|
||||
"number": 1,
|
||||
"rssi": 40,
|
||||
"setTemp": 24,
|
||||
"state": "open",
|
||||
"type": 1,
|
||||
"value": 100
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"system": {
|
||||
"hasAircons": false,
|
||||
"hasLights": false,
|
||||
"hasSensors": false,
|
||||
"hasThings": false,
|
||||
"hasThingsBOG": false,
|
||||
"hasThingsLight": false,
|
||||
"needsUpdate": true,
|
||||
"name": "testname",
|
||||
"rid": "uniqueid",
|
||||
"sysType": "e-zone",
|
||||
"myAppRev": "1.234"
|
||||
}
|
||||
}
|
28
tests/components/advantage_air/test_update.py
Normal file
28
tests/components/advantage_air/test_update.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
"""Test the Advantage Air Update Platform."""
|
||||
|
||||
from homeassistant.const import STATE_ON
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from tests.common import load_fixture
|
||||
from tests.components.advantage_air import TEST_SYSTEM_URL, add_mock_config
|
||||
|
||||
|
||||
async def test_update_platform(hass, aioclient_mock):
|
||||
"""Test update platform."""
|
||||
|
||||
aioclient_mock.get(
|
||||
TEST_SYSTEM_URL,
|
||||
text=load_fixture("advantage_air/needsUpdate.json"),
|
||||
)
|
||||
await add_mock_config(hass)
|
||||
|
||||
registry = er.async_get(hass)
|
||||
|
||||
entity_id = "update.testname_app"
|
||||
state = hass.states.get(entity_id)
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
|
||||
entry = registry.async_get(entity_id)
|
||||
assert entry
|
||||
assert entry.unique_id == "uniqueid"
|
Loading…
Add table
Reference in a new issue