From efdb54cbe4bb3f1c8e5e3b256913130fbdd6c1fc Mon Sep 17 00:00:00 2001 From: jamespcole Date: Mon, 9 Mar 2015 05:28:12 +1100 Subject: [PATCH 01/42] Added in SABnzbd sensor --- .gitmodules | 3 + homeassistant/components/sensor/sabnzbd.py | 142 +++++++++++++++++++++ homeassistant/external/nzbclients | 1 + 3 files changed, 146 insertions(+) create mode 100644 homeassistant/components/sensor/sabnzbd.py create mode 160000 homeassistant/external/nzbclients diff --git a/.gitmodules b/.gitmodules index 6e49e76698a..27b3cae6bf8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,6 @@ [submodule "homeassistant/components/frontend/www_static/polymer/home-assistant-js"] path = homeassistant/components/frontend/www_static/polymer/home-assistant-js url = https://github.com/balloob/home-assistant-js.git +[submodule "homeassistant/external/nzbclients"] + path = homeassistant/external/nzbclients + url = https://github.com/jamespcole/home-assistant-nzb-clients.git diff --git a/homeassistant/components/sensor/sabnzbd.py b/homeassistant/components/sensor/sabnzbd.py new file mode 100644 index 00000000000..f07cd0e62a0 --- /dev/null +++ b/homeassistant/components/sensor/sabnzbd.py @@ -0,0 +1,142 @@ +""" +homeassistant.components.sensor.sabnzbd +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Monitors SABnzbd NZB client API + +Configuration: + +To use the SABnzbd sensor you will need to add something like the following to +your config/configuration.yaml + +sensor: + platform: sabnzbd + name: SAB + api_key: YOUR_API_KEY + base_url: YOUR_SABNZBD_BASE_URL + monitored_variables: + - type: 'current_status' + - type: 'speed' + - type: 'queue_size' + - type: 'queue_remaining' + - type: 'disk_size' + - type: 'disk_free' + +VARIABLES: + +base_url +*Required +This is the base URL of your SABnzbd instance including the port number if not +running on 80 +Example: http://192.168.1.32:8124/ + + +name +*Optional +The name to use when displaying this SABnzbd instance + +monitored_variables +*Required +An array specifying the variables to monitor. + +These are the variables for the monitored_variables array: + +type +*Required +The variable you wish to monitor, see the configuration example above for a +list of all available variables + + +""" + +from homeassistant.helpers.device import Device +# pylint: disable=no-name-in-module, import-error +from homeassistant.external.nzbclients.sabnzbd import SabnzbdApi +from homeassistant.const import ( + ATTR_UNIT_OF_MEASUREMENT, ATTR_FRIENDLY_NAME) +import logging + + +SENSOR_TYPES = { + 'current_status': ['Status', ''], + 'speed': ['Speed', 'MB/s'], + 'queue_size': ['Queue', 'MB'], + 'queue_remaining': ['Left', 'MB'], + 'disk_size': ['Disk', 'GB'], + 'disk_free': ['Disk Free', 'GB'], +} + +_LOGGER = logging.getLogger(__name__) + + +# pylint: disable=unused-argument +def setup_platform(hass, config, add_devices, discovery_info=None): + """ Sets up the sensors """ + api_key = config.get("api_key") + base_url = config.get("base_url") + name = config.get("name", "SABnzbd") + if not base_url: + _LOGGER.error('Missing config variable base_url') + return False + if not api_key: + _LOGGER.error('Missing config variable api_key') + return False + + sab_api = SabnzbdApi(base_url, api_key) + dev = [] + for variable in config['monitored_variables']: + if variable['type'] not in SENSOR_TYPES: + _LOGGER.error('Sensor type: "%s" does not exist', variable['type']) + else: + dev.append(SabnzbdSensor(variable['type'], sab_api, name)) + + add_devices(dev) + + +class SabnzbdSensor(Device): + """ A Sabnzbd sensor """ + + def __init__(self, sensor_type, sabnzb_client, client_name): + self._name = SENSOR_TYPES[sensor_type][0] + self.sabnzb_client = sabnzb_client + self.type = sensor_type + self.client_name = client_name + self._state = None + self.unit_of_measurement = SENSOR_TYPES[sensor_type][1] + self.update() + + @property + def name(self): + return self.client_name + ' ' + self._name + + @property + def state(self): + """ 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): + self.sabnzb_client.refresh_queue() + if self.sabnzb_client.queue: + if self.type == 'current_status': + self._state = self.sabnzb_client.queue.get('status') + elif self.type == 'speed': + mb_spd = float(self.sabnzb_client.queue.get('kbpersec')) / 1024 + self._state = round(mb_spd, 1) + elif self.type == 'queue_size': + self._state = self.sabnzb_client.queue.get('mb') + elif self.type == 'queue_remaining': + self._state = self.sabnzb_client.queue.get('mbleft') + elif self.type == 'disk_size': + self._state = self.sabnzb_client.queue.get('diskspacetotal1') + elif self.type == 'disk_free': + self._state = self.sabnzb_client.queue.get('diskspace1') + else: + self._state = 'Unknown' diff --git a/homeassistant/external/nzbclients b/homeassistant/external/nzbclients new file mode 160000 index 00000000000..f9f9ba36934 --- /dev/null +++ b/homeassistant/external/nzbclients @@ -0,0 +1 @@ +Subproject commit f9f9ba36934f087b9c4241303b900794a7eb6c08 From 046efe3acbfe4c2efcab915d342ab11dc94708bf Mon Sep 17 00:00:00 2001 From: andythigpen Date: Sat, 7 Mar 2015 21:14:21 -0600 Subject: [PATCH 02/42] Adds script component. A script is composed of a sequence of actions (currently service calls) that are executed in order. Individual actions can also be delayed by a given timedelta. --- config/configuration.yaml.example | 20 ++- homeassistant/__init__.py | 2 + .../polymer/layouts/home-assistant-main.html | 24 ++- .../layouts/partial-dev-call-service.html | 2 +- .../polymer/layouts/partial-states.html | 14 +- .../polymer/more-infos/more-info-content.html | 1 + .../polymer/more-infos/more-info-script.html | 22 +++ .../resources/home-assistant-icons.html | 3 + .../polymer/resources/home-assistant-js.html | 2 +- homeassistant/components/script.py | 140 ++++++++++++++++++ 10 files changed, 223 insertions(+), 7 deletions(-) create mode 100644 homeassistant/components/frontend/www_static/polymer/more-infos/more-info-script.html create mode 100644 homeassistant/components/script.py diff --git a/config/configuration.yaml.example b/config/configuration.yaml.example index c758833d336..49886682507 100644 --- a/config/configuration.yaml.example +++ b/config/configuration.yaml.example @@ -120,4 +120,22 @@ sensor: - type: 'memory_free' - type: 'processor_use' - type: 'process' - arg: 'octave-cli' \ No newline at end of file + arg: 'octave-cli' + +script: + # Turns on the bedroom lights and then the living room lights 1 minute later + wakeup: + alias: Wake Up + sequence: + # alias is optional + - alias: Bedroom lights on + execute_service: light.turn_on + service_data: + entity_id: group.bedroom + - delay: + # supports seconds, milliseconds, minutes, hours, etc. + minutes: 1 + - alias: Living room lights on + execute_service: light.turn_on + service_data: + entity_id: group.living_room diff --git a/homeassistant/__init__.py b/homeassistant/__init__.py index 354898c0319..0d41e7dd2e6 100644 --- a/homeassistant/__init__.py +++ b/homeassistant/__init__.py @@ -115,6 +115,7 @@ class HomeAssistant(object): action(now) self.bus.listen(EVENT_TIME_CHANGED, point_in_time_listener) + return point_in_time_listener # pylint: disable=too-many-arguments def track_time_change(self, action, @@ -154,6 +155,7 @@ class HomeAssistant(object): action(event.data[ATTR_NOW]) self.bus.listen(EVENT_TIME_CHANGED, time_listener) + return time_listener def stop(self): """ Stops Home Assistant and shuts down all threads. """ diff --git a/homeassistant/components/frontend/www_static/polymer/layouts/home-assistant-main.html b/homeassistant/components/frontend/www_static/polymer/layouts/home-assistant-main.html index 73be6cb166d..3a8730dac8b 100644 --- a/homeassistant/components/frontend/www_static/polymer/layouts/home-assistant-main.html +++ b/homeassistant/components/frontend/www_static/polymer/layouts/home-assistant-main.html @@ -93,6 +93,13 @@ + +
@@ -124,10 +131,10 @@ This is the main partial, never remove it from the DOM but hide it to speed up when people click on states. --> - + filter="{{selected}}">