Black
This commit is contained in:
parent
da05dfe708
commit
4de97abc3a
2676 changed files with 163166 additions and 140084 deletions
|
@ -2,21 +2,29 @@
|
|||
import logging
|
||||
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION, ATTR_LATITUDE, ATTR_LONGITUDE, CONF_SHOW_ON_MAP)
|
||||
ATTR_ATTRIBUTION,
|
||||
ATTR_LATITUDE,
|
||||
ATTR_LONGITUDE,
|
||||
CONF_SHOW_ON_MAP,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from . import (
|
||||
DATA_LUFTDATEN, DATA_LUFTDATEN_CLIENT, DEFAULT_ATTRIBUTION, DOMAIN,
|
||||
SENSORS, TOPIC_UPDATE)
|
||||
DATA_LUFTDATEN,
|
||||
DATA_LUFTDATEN_CLIENT,
|
||||
DEFAULT_ATTRIBUTION,
|
||||
DOMAIN,
|
||||
SENSORS,
|
||||
TOPIC_UPDATE,
|
||||
)
|
||||
from .const import ATTR_SENSOR_ID
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass, config, async_add_entities, discovery_info=None):
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up an Luftdaten sensor based on existing config."""
|
||||
pass
|
||||
|
||||
|
@ -30,8 +38,9 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||
name, icon, unit = SENSORS[sensor_type]
|
||||
sensors.append(
|
||||
LuftdatenSensor(
|
||||
luftdaten, sensor_type, name, icon, unit,
|
||||
entry.data[CONF_SHOW_ON_MAP]))
|
||||
luftdaten, sensor_type, name, icon, unit, entry.data[CONF_SHOW_ON_MAP]
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(sensors, True)
|
||||
|
||||
|
@ -39,8 +48,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||
class LuftdatenSensor(Entity):
|
||||
"""Implementation of a Luftdaten sensor."""
|
||||
|
||||
def __init__(
|
||||
self, luftdaten, sensor_type, name, icon, unit, show):
|
||||
def __init__(self, luftdaten, sensor_type, name, icon, unit, show):
|
||||
"""Initialize the Luftdaten sensor."""
|
||||
self._async_unsub_dispatcher_connect = None
|
||||
self.luftdaten = luftdaten
|
||||
|
@ -77,7 +85,7 @@ class LuftdatenSensor(Entity):
|
|||
def unique_id(self) -> str:
|
||||
"""Return a unique, friendly identifier for this entity."""
|
||||
if self._data is not None:
|
||||
return '{0}_{1}'.format(self._data['sensor_id'], self.sensor_type)
|
||||
return "{0}_{1}".format(self._data["sensor_id"], self.sensor_type)
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
|
@ -85,27 +93,29 @@ class LuftdatenSensor(Entity):
|
|||
self._attrs[ATTR_ATTRIBUTION] = DEFAULT_ATTRIBUTION
|
||||
|
||||
if self._data is not None:
|
||||
self._attrs[ATTR_SENSOR_ID] = self._data['sensor_id']
|
||||
self._attrs[ATTR_SENSOR_ID] = self._data["sensor_id"]
|
||||
|
||||
on_map = ATTR_LATITUDE, ATTR_LONGITUDE
|
||||
no_map = 'lat', 'long'
|
||||
no_map = "lat", "long"
|
||||
lat_format, lon_format = on_map if self._show_on_map else no_map
|
||||
try:
|
||||
self._attrs[lon_format] = self._data['longitude']
|
||||
self._attrs[lat_format] = self._data['latitude']
|
||||
self._attrs[lon_format] = self._data["longitude"]
|
||||
self._attrs[lat_format] = self._data["latitude"]
|
||||
return self._attrs
|
||||
except KeyError:
|
||||
return
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
|
||||
@callback
|
||||
def update():
|
||||
"""Update the state."""
|
||||
self.async_schedule_update_ha_state(True)
|
||||
|
||||
self._async_unsub_dispatcher_connect = async_dispatcher_connect(
|
||||
self.hass, TOPIC_UPDATE, update)
|
||||
self.hass, TOPIC_UPDATE, update
|
||||
)
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
"""Disconnect dispatcher listener when removed."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue