pull/4939/head
Fabian Affolter 2016-12-16 07:12:33 +01:00 committed by Paulus Schoutsen
parent 5b70ada7b4
commit 2a31bb48c6
1 changed files with 22 additions and 20 deletions

View File

@ -1,23 +1,25 @@
"""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/
"""
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/
"""
import json
import logging
from homeassistant.helpers.entity import Entity
import homeassistant.components.mqtt as mqtt
from homeassistant.const import (TEMP_FAHRENHEIT, TEMP_CELSIUS)
from homeassistant.helpers.entity import Entity
from homeassistant.util import slugify
DEPENDENCIES = ['mqtt']
_LOGGER = logging.getLogger(__name__)
DEPENDENCIES = ['mqtt']
DOMAIN = 'arwn'
DOMAIN = "arwn"
TOPIC = 'arwn/#'
SENSORS = {}
_LOGGER = logging.getLogger(__name__)
TOPIC = 'arwn/#'
def discover_sensors(topic, payload):
@ -25,23 +27,23 @@ def discover_sensors(topic, payload):
parts = topic.split('/')
unit = payload.get('units', '')
domain = parts[1]
if domain == "temperature":
if domain == 'temperature':
name = parts[2]
if unit == "F":
if unit == 'F':
unit = TEMP_FAHRENHEIT
else:
unit = TEMP_CELSIUS
return (ArwnSensor(name, 'temp', unit),)
if domain == "barometer":
return (ArwnSensor("Barometer", 'pressure', unit),)
if domain == "wind":
return (ArwnSensor("Wind Speed", 'speed', unit),
ArwnSensor("Wind Gust", 'gust', unit),
ArwnSensor("Wind Direction", 'direction', '°'))
return ArwnSensor(name, 'temp', unit)
if domain == 'barometer':
return ArwnSensor('Barometer', 'pressure', unit)
if domain == 'wind':
return (ArwnSensor('Wind Speed', 'speed', unit),
ArwnSensor('Wind Gust', 'gust', unit),
ArwnSensor('Wind Direction', 'direction', '°'))
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):
@ -84,7 +86,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class ArwnSensor(Entity):
"""Represents an ARWN sensor."""
"""Representation of an ARWN sensor."""
def __init__(self, name, state_key, units):
"""Initialize the sensor."""