Clean-up (#4894)
parent
5b70ada7b4
commit
2a31bb48c6
|
@ -1,23 +1,25 @@
|
||||||
"""Support for collecting data from the ARWN project.
|
"""
|
||||||
|
Support for collecting data from the ARWN project.
|
||||||
For more details about this platform, please refer to the
|
|
||||||
documentation at https://home-assistant.io/components/sensor.arwn/
|
|
||||||
|
|
||||||
|
For more details about this platform, please refer to the documentation at
|
||||||
|
https://home-assistant.io/components/sensor.arwn/
|
||||||
"""
|
"""
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from homeassistant.helpers.entity import Entity
|
|
||||||
import homeassistant.components.mqtt as mqtt
|
import homeassistant.components.mqtt as mqtt
|
||||||
from homeassistant.const import (TEMP_FAHRENHEIT, TEMP_CELSIUS)
|
from homeassistant.const import (TEMP_FAHRENHEIT, TEMP_CELSIUS)
|
||||||
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify
|
||||||
|
|
||||||
DEPENDENCIES = ['mqtt']
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
DEPENDENCIES = ['mqtt']
|
||||||
|
DOMAIN = 'arwn'
|
||||||
|
|
||||||
DOMAIN = "arwn"
|
|
||||||
TOPIC = 'arwn/#'
|
|
||||||
SENSORS = {}
|
SENSORS = {}
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
TOPIC = 'arwn/#'
|
||||||
|
|
||||||
|
|
||||||
def discover_sensors(topic, payload):
|
def discover_sensors(topic, payload):
|
||||||
|
@ -25,23 +27,23 @@ def discover_sensors(topic, payload):
|
||||||
parts = topic.split('/')
|
parts = topic.split('/')
|
||||||
unit = payload.get('units', '')
|
unit = payload.get('units', '')
|
||||||
domain = parts[1]
|
domain = parts[1]
|
||||||
if domain == "temperature":
|
if domain == 'temperature':
|
||||||
name = parts[2]
|
name = parts[2]
|
||||||
if unit == "F":
|
if unit == 'F':
|
||||||
unit = TEMP_FAHRENHEIT
|
unit = TEMP_FAHRENHEIT
|
||||||
else:
|
else:
|
||||||
unit = TEMP_CELSIUS
|
unit = TEMP_CELSIUS
|
||||||
return (ArwnSensor(name, 'temp', unit),)
|
return ArwnSensor(name, 'temp', unit)
|
||||||
if domain == "barometer":
|
if domain == 'barometer':
|
||||||
return (ArwnSensor("Barometer", 'pressure', unit),)
|
return ArwnSensor('Barometer', 'pressure', unit)
|
||||||
if domain == "wind":
|
if domain == 'wind':
|
||||||
return (ArwnSensor("Wind Speed", 'speed', unit),
|
return (ArwnSensor('Wind Speed', 'speed', unit),
|
||||||
ArwnSensor("Wind Gust", 'gust', unit),
|
ArwnSensor('Wind Gust', 'gust', unit),
|
||||||
ArwnSensor("Wind Direction", 'direction', '°'))
|
ArwnSensor('Wind Direction', 'direction', '°'))
|
||||||
|
|
||||||
|
|
||||||
def _slug(name):
|
def _slug(name):
|
||||||
return "sensor.arwn_%s" % slugify(name)
|
return 'sensor.arwn_{}'.format(slugify(name))
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
@ -84,7 +86,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
|
|
||||||
class ArwnSensor(Entity):
|
class ArwnSensor(Entity):
|
||||||
"""Represents an ARWN sensor."""
|
"""Representation of an ARWN sensor."""
|
||||||
|
|
||||||
def __init__(self, name, state_key, units):
|
def __init__(self, name, state_key, units):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
|
|
Loading…
Reference in New Issue