StarLine integration (#27197)

* Device Tracker works

* Device Tracker works

* Binary Sensor

* Sensor

* Lock

* Switch and service

* New switches

* Update interval options

* WIP

* Translation errors

* Check online state

* WIP

* Move to aiohttp

* Some checks

* CI

* CI

* .coveragerc

* Black

* icon_for_signal_level test

* update_interval renamed to scan_interval

* async logic

* Fix cookie read

* Requirement starline

* Reformat

* Requirements updated

* ConfigEntryNotReady

* Requirement starline

* Lint fix

* Requirement starline

* available status

* Translations

* Expiration to config

* CI

* Linter fix

* Small renaming

* Update slnet token

* Starline version bump

* Fix updates

* Black

* Small fix

* Removed unused fields

* CI

* set_scan_interval service

* deps updated

* Horn switch

* Starline lib updated

* Starline lib updated

* Black

* Support multiple integrations

* Review

* async_will_remove_from_hass

* Deps updated

* Test config flow

* Requirements

* CI

* Review

* Review

* Review

* Review

* Review

* CI

* pylint fix

* Review

* Support "mayak" devices

* Icons removed

* Removed options_flow

* Removed options_flow test

* Removed options_flow test
This commit is contained in:
Nikolay Vasilchuk 2019-11-26 22:17:11 +03:00 committed by Paulus Schoutsen
parent c21650473a
commit a37260faa9
23 changed files with 1179 additions and 0 deletions

View file

@ -0,0 +1,59 @@
"""StarLine base entity."""
from typing import Callable, Optional
from homeassistant.helpers.entity import Entity
from .account import StarlineAccount, StarlineDevice
class StarlineEntity(Entity):
"""StarLine base entity class."""
def __init__(
self, account: StarlineAccount, device: StarlineDevice, key: str, name: str
):
"""Constructor."""
self._account = account
self._device = device
self._key = key
self._name = name
self._unsubscribe_api: Optional[Callable] = None
@property
def should_poll(self):
"""No polling needed."""
return False
@property
def available(self):
"""Return True if entity is available."""
return self._account.api.available
@property
def unique_id(self):
"""Return the unique ID of the entity."""
return f"starline-{self._key}-{self._device.device_id}"
@property
def name(self):
"""Return the name of the entity."""
return f"{self._device.name} {self._name}"
@property
def device_info(self):
"""Return the device info."""
return self._account.device_info(self._device)
def update(self):
"""Read new state data."""
self.schedule_update_ha_state()
async def async_added_to_hass(self):
"""Call when entity about to be added to Home Assistant."""
await super().async_added_to_hass()
self._unsubscribe_api = self._account.api.add_update_listener(self.update)
async def async_will_remove_from_hass(self):
"""Call when entity is being removed from Home Assistant."""
await super().async_will_remove_from_hass()
if self._unsubscribe_api is not None:
self._unsubscribe_api()
self._unsubscribe_api = None