Spring cleaning ☀️ (#23)

* Spring cleaning

* Actions

* Fix branches

* Changes for config_flow
This commit is contained in:
Joakim Sørensen
2020-04-17 19:42:59 +02:00
committed by GitHub
parent d408fbec4a
commit a53b0f75a1
28 changed files with 349 additions and 731 deletions

View File

@ -1,79 +1,28 @@
"""Sensor platform for blueprint."""
from homeassistant.helpers.entity import Entity
from .const import ATTRIBUTION, DEFAULT_NAME, DOMAIN_DATA, ICON, DOMAIN
from custom_components.blueprint.const import DEFAULT_NAME, DOMAIN, ICON, SENSOR
from custom_components.blueprint.entity import BlueprintEntity
async def async_setup_platform(
hass, config, async_add_entities, discovery_info=None
): # pylint: disable=unused-argument
async def async_setup_entry(hass, entry, async_add_devices):
"""Setup sensor platform."""
async_add_entities([BlueprintSensor(hass, discovery_info)], True)
coordinator = hass.data[DOMAIN][entry.entry_id]
async_add_devices([BlueprintSensor(coordinator, entry)])
async def async_setup_entry(hass, config_entry, async_add_devices):
"""Setup sensor platform."""
async_add_devices([BlueprintSensor(hass, {})], True)
class BlueprintSensor(Entity):
class BlueprintSensor(BlueprintEntity):
"""blueprint Sensor class."""
def __init__(self, hass, config):
self.hass = hass
self.attr = {}
self._state = None
self._name = config.get("name", DEFAULT_NAME)
async def async_update(self):
"""Update the sensor."""
# Send update "signal" to the component
await self.hass.data[DOMAIN_DATA]["client"].update_data()
# Get new data (if any)
updated = self.hass.data[DOMAIN_DATA]["data"].get("data", {})
# Check the data and update the value.
if updated.get("static") is None:
self._state = self._state
else:
self._state = updated.get("static")
# Set/update attributes
self.attr["attribution"] = ATTRIBUTION
self.attr["time"] = str(updated.get("time"))
self.attr["none"] = updated.get("none")
@property
def unique_id(self):
"""Return a unique ID to use for this sensor."""
return (
"0717a0cd-745c-48fd"
) # Don't hard code this, use something from the device/service.
@property
def device_info(self):
return {
"identifiers": {(DOMAIN, self.unique_id)},
"name": self.name,
"manufacturer": "Blueprint",
}
@property
def name(self):
"""Return the name of the sensor."""
return self._name
return f"{DEFAULT_NAME}_{SENSOR}"
@property
def state(self):
"""Return the state of the sensor."""
return self._state
return self.coordinator.data.get("static")
@property
def icon(self):
"""Return the icon of the sensor."""
return ICON
@property
def device_state_attributes(self):
"""Return the state attributes."""
return self.attr