Add Hive config flow (#47300)

* Add Hive UI

* Fix tests and review updates

* Slimmed down config_flow

* Fix tests

* Updated Services.yaml with extra ui attributes

* cleanup config flow

* Update config entry

* Remove ATTR_AVAILABLE

* Fix Re-Auth  Test

* Added more tests.

* Update tests
This commit is contained in:
Khole 2021-03-15 11:27:10 +00:00 committed by GitHub
parent 1aa4fd4cc9
commit cfeb8eb06a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 1165 additions and 201 deletions

View file

@ -5,7 +5,8 @@ from datetime import timedelta
from homeassistant.components.sensor import DEVICE_CLASS_BATTERY
from homeassistant.helpers.entity import Entity
from . import ATTR_AVAILABLE, DATA_HIVE, DOMAIN, HiveEntity
from . import HiveEntity
from .const import DOMAIN
PARALLEL_UPDATES = 0
SCAN_INTERVAL = timedelta(seconds=15)
@ -14,18 +15,15 @@ DEVICETYPE = {
}
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Hive Sensor."""
if discovery_info is None:
return
async def async_setup_entry(hass, entry, async_add_entities):
"""Set up Hive thermostat based on a config entry."""
hive = hass.data[DOMAIN].get(DATA_HIVE)
devices = hive.devices.get("sensor")
hive = hass.data[DOMAIN][entry.entry_id]
devices = hive.session.deviceList.get("sensor")
entities = []
if devices:
for dev in devices:
if dev["hiveType"] in DEVICETYPE:
entities.append(HiveSensorEntity(hive, dev))
entities.append(HiveSensorEntity(hive, dev))
async_add_entities(entities, True)
@ -40,7 +38,14 @@ class HiveSensorEntity(HiveEntity, Entity):
@property
def device_info(self):
"""Return device information."""
return {"identifiers": {(DOMAIN, self.unique_id)}, "name": self.name}
return {
"identifiers": {(DOMAIN, self.device["device_id"])},
"name": self.device["device_name"],
"model": self.device["deviceData"]["model"],
"manufacturer": self.device["deviceData"]["manufacturer"],
"sw_version": self.device["deviceData"]["version"],
"via_device": (DOMAIN, self.device["parentDevice"]),
}
@property
def available(self):
@ -67,12 +72,7 @@ class HiveSensorEntity(HiveEntity, Entity):
"""Return the state of the sensor."""
return self.device["status"]["state"]
@property
def extra_state_attributes(self):
"""Return the state attributes."""
return {ATTR_AVAILABLE: self.attributes.get(ATTR_AVAILABLE)}
async def async_update(self):
"""Update all Node data from Hive."""
await self.hive.session.updateData(self.device)
self.device = await self.hive.sensor.get_sensor(self.device)
self.device = await self.hive.sensor.getSensor(self.device)