ps: Add a global config object to Home Assistant
This commit is contained in:
1 parent
569b15d790
commit
9b643d57f0
23 files changed
+224
-173
No files matched your search
@@ -1,25 +1,25 @@
|
||||
""" Support for Wink sensors. """
|
||||
from homeassistant.helpers.device import Device
|
||||
from homeassistant.const import (
|
||||
TEMP_CELCIUS, ATTR_UNIT_OF_MEASUREMENT, ATTR_FRIENDLY_NAME)
|
||||
from homeassistant.const import TEMP_CELCIUS, ATTR_BATTERY_LEVEL
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
""" Sets up the Demo sensors. """
|
||||
add_devices([
|
||||
DemoSensor('Outside Temperature', 15.6, TEMP_CELCIUS),
|
||||
DemoSensor('Outside Humidity', 54, '%'),
|
||||
DemoSensor('Outside Temperature', 15.6, TEMP_CELCIUS, 12),
|
||||
DemoSensor('Outside Humidity', 54, '%', None),
|
||||
])
|
||||
|
||||
|
||||
class DemoSensor(Device):
|
||||
""" A Demo sensor. """
|
||||
|
||||
def __init__(self, name, state, unit_of_measurement):
|
||||
def __init__(self, name, state, unit_of_measurement, battery):
|
||||
self._name = name
|
||||
self._state = state
|
||||
self._unit_of_measurement = unit_of_measurement
|
||||
self._battery = battery
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
@@ -36,10 +36,15 @@ class DemoSensor(Device):
|
||||
""" Returns the state of the device. """
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
""" Unit this state is expressed in. """
|
||||
return self._unit_of_measurement
|
||||
|
||||
@property
|
||||
def state_attributes(self):
|
||||
""" Returns the state attributes. """
|
||||
return {
|
||||
ATTR_FRIENDLY_NAME: self._name,
|
||||
ATTR_UNIT_OF_MEASUREMENT: self._unit_of_measurement,
|
||||
}
|
||||
if self._battery:
|
||||
return {
|
||||
ATTR_BATTERY_LEVEL: self._battery,
|
||||
}
|
||||
@@ -7,8 +7,7 @@ Shows system monitor values such as: disk, memory and processor use
|
||||
"""
|
||||
|
||||
from homeassistant.helpers.device import Device
|
||||
from homeassistant.const import (
|
||||
ATTR_UNIT_OF_MEASUREMENT, ATTR_FRIENDLY_NAME, STATE_ON, STATE_OFF)
|
||||
from homeassistant.const import STATE_ON, STATE_OFF
|
||||
import psutil
|
||||
import logging
|
||||
|
||||
@@ -63,14 +62,6 @@ class SystemMonitorSensor(Device):
|
||||
""" Returns the state of the device. """
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def state_attributes(self):
|
||||
""" Returns the state attributes. """
|
||||
return {
|
||||
ATTR_FRIENDLY_NAME: self.name,
|
||||
ATTR_UNIT_OF_MEASUREMENT: self.unit_of_measurement,
|
||||
}
|
||||
|
||||
def update(self):
|
||||
if self.type == 'disk_use_percent':
|
||||
self._state = psutil.disk_usage(self.argument).percent
|
||||
|
||||
@@ -29,8 +29,7 @@ from collections import namedtuple
|
||||
import tellcore.telldus as telldus
|
||||
import tellcore.constants as tellcore_constants
|
||||
|
||||
from homeassistant.const import (
|
||||
ATTR_FRIENDLY_NAME, ATTR_UNIT_OF_MEASUREMENT, TEMP_CELCIUS)
|
||||
from homeassistant.const import TEMP_CELCIUS
|
||||
from homeassistant.helpers.device import Device
|
||||
|
||||
DatatypeDescription = namedtuple("DatatypeDescription", ['name', 'unit'])
|
||||
@@ -99,7 +98,7 @@ class TellstickSensor(Device):
|
||||
def __init__(self, name, sensor, datatype, sensor_info):
|
||||
self.datatype = datatype
|
||||
self.sensor = sensor
|
||||
self.unit = sensor_info.unit or None
|
||||
self.unit_of_measurement = sensor_info.unit or None
|
||||
|
||||
self._name = "{} {}".format(name, sensor_info.name)
|
||||
|
||||
@@ -112,15 +111,3 @@ class TellstickSensor(Device):
|
||||
def state(self):
|
||||
""" Returns the state of the device. """
|
||||
return self.sensor.value(self.datatype).value
|
||||
|
||||
@property
|
||||
def state_attributes(self):
|
||||
""" Returns the state attributes. """
|
||||
attrs = {
|
||||
ATTR_FRIENDLY_NAME: self._name,
|
||||
}
|
||||
|
||||
if self.unit:
|
||||
attrs[ATTR_UNIT_OF_MEASUREMENT] = self.unit
|
||||
|
||||
return attrs
|
||||
@@ -4,8 +4,8 @@ import logging
|
||||
# pylint: disable=no-name-in-module, import-error
|
||||
import homeassistant.external.wink.pywink as pywink
|
||||
|
||||
from homeassistant.components.wink import WinkSensorDevice
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN
|
||||
from homeassistant.helpers.device import Device
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN, STATE_OPEN, STATE_CLOSED
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
@@ -22,3 +22,34 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
pywink.set_bearer_token(token)
|
||||
|
||||
add_devices(WinkSensorDevice(sensor) for sensor in pywink.get_sensors())
|
||||
|
||||
|
||||
class WinkSensorDevice(Device):
|
||||
""" represents a wink sensor within home assistant. """
|
||||
|
||||
def __init__(self, wink):
|
||||
self.wink = wink
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
""" Returns the state. """
|
||||
return STATE_OPEN if self.is_open else STATE_CLOSED
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
""" Returns the id of this wink sensor """
|
||||
return "{}.{}".format(self.__class__, self.wink.deviceId())
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" Returns the name of the sensor if any. """
|
||||
return self.wink.name()
|
||||
|
||||
def update(self):
|
||||
""" Update state of the sensor. """
|
||||
self.wink.updateState()
|
||||
|
||||
@property
|
||||
def is_open(self):
|
||||
""" True if door is open. """
|
||||
return self.wink.state()
|
||||
@@ -11,7 +11,7 @@ from pydispatch import dispatcher
|
||||
import homeassistant.components.zwave as zwave
|
||||
from homeassistant.helpers.device import Device
|
||||
from homeassistant.const import (
|
||||
ATTR_BATTERY_LEVEL, ATTR_UNIT_OF_MEASUREMENT, STATE_ON, STATE_OFF,
|
||||
ATTR_BATTERY_LEVEL, STATE_ON, STATE_OFF,
|
||||
TEMP_CELCIUS, TEMP_FAHRENHEIT, ATTR_LOCATION)
|
||||
|
||||
|
||||
@@ -77,11 +77,6 @@ class ZWaveSensor(Device):
|
||||
if battery_level is not None:
|
||||
attrs[ATTR_BATTERY_LEVEL] = battery_level
|
||||
|
||||
unit = self.unit
|
||||
|
||||
if unit:
|
||||
attrs[ATTR_UNIT_OF_MEASUREMENT] = unit
|
||||
|
||||
location = self._node.location
|
||||
|
||||
if location:
|
||||
@@ -90,8 +85,7 @@ class ZWaveSensor(Device):
|
||||
return attrs
|
||||
|
||||
@property
|
||||
def unit(self):
|
||||
""" Unit if sensor has one. """
|
||||
def unit_of_measurement(self):
|
||||
return self._value.units
|
||||
|
||||
def _value_changed(self, value):
|
||||
@@ -126,8 +120,7 @@ class ZWaveMultilevelSensor(ZWaveSensor):
|
||||
return value
|
||||
|
||||
@property
|
||||
def unit(self):
|
||||
""" Unit of this sensor. """
|
||||
def unit_of_measurement(self):
|
||||
unit = self._value.units
|
||||
|
||||
if unit == 'C':
|
||||
|
||||
Reference in new issue
Block a user