hass-core/homeassistant/components/juicenet/entity.py
Jesse Hills e696c08db0
Rewrite JuiceNet for async and config flow ()
* Add config flow to JuiceNet

* Fix some lint issues

* Fix imports

* Abort on reconfigure / Allow multiple accounts
Abort on bad API token
Fix strings

* Remove unused variable

* Update strings

* Remove import

* Fix import order again

* Update imports
Remove some unused parameters

* Add back ignore

* Update config_flow.py

* iSort

* Update juicenet integration to be async

* Update coverage for juicenet config flow

* Update homeassistant/components/juicenet/entity.py

Co-Authored-By: J. Nick Koston <nick@koston.org>

* Black

* Make imports relative

* Rename translations folder

Co-authored-by: J. Nick Koston <nick@koston.org>
2020-05-08 00:52:20 -05:00

54 lines
1.5 KiB
Python

"""Adapter to wrap the pyjuicenet api for home assistant."""
from homeassistant.helpers.entity import Entity
from .const import DOMAIN
class JuiceNetDevice(Entity):
"""Represent a base JuiceNet device."""
def __init__(self, device, sensor_type, coordinator):
"""Initialise the sensor."""
self.device = device
self.type = sensor_type
self.coordinator = coordinator
@property
def name(self):
"""Return the name of the device."""
return self.device.name
@property
def should_poll(self):
"""Return False, updates are controlled via coordinator."""
return False
@property
def available(self):
"""Return True if entity is available."""
return self.coordinator.last_update_success
async def async_update(self):
"""Update the entity."""
await self.coordinator.async_request_refresh()
async def async_added_to_hass(self):
"""Subscribe to updates."""
self.async_on_remove(
self.coordinator.async_add_listener(self.async_write_ha_state)
)
@property
def unique_id(self):
"""Return a unique ID."""
return f"{self.device.id}-{self.type}"
@property
def device_info(self):
"""Return device information about this JuiceNet Device."""
return {
"identifiers": {(DOMAIN, self.device.id)},
"name": self.device.name,
"manufacturer": "JuiceNet",
}