diff --git a/README.md b/README.md index 42b8a06..af333a8 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,15 @@ # Hue-sensors-HASS -Component for Hue sensors in Home-assistant. +Component for Hue sensors in Home-assistant v0.6 and above. -Place the custom_components folder in your configuration directory (or add its contents to an existing custom_components folder). Please note you are adding a hub and the sensors in the config instructions below, both are required. Additionally setup assumes have the file phue.conf in your hass config dir, which is created by the hue lights component (different author). Hopefully the sensors and lights can be unified with some more work. +Place the custom_components folder in your configuration directory (or add its contents to an existing custom_components folder). Setup assumes you have the file phue.conf in your hass config dir, which is created by the hue lights component (different author). Note that in some cases phue.conf may be named differently, for example mine was something like phue-12412523.conf so I copied and pasted this file, then renamed to phue.conf. Hue dimmer remotes can be used for a click and long press (hold button for 2 sec and see LED blink twice). Add to your config: ``` -hue: - sensor: - - platform: hue + - platform: hue_sensor ``` To add the following group to your HA frontend, add the following to groups.yaml (obviously editing to use your sensors): diff --git a/custom_components/hue.py b/custom_components/hue.py deleted file mode 100644 index 5bb0062..0000000 --- a/custom_components/hue.py +++ /dev/null @@ -1,34 +0,0 @@ -""" -Support for Hue components. - -For more details about this platform, please refer to the documentation at -https://home-assistant.io/components/hue/ -""" -import json -import logging - -from homeassistant.const import (CONF_FILENAME) - -_LOGGER = logging.getLogger(__name__) -PHUE_CONFIG_FILE = 'phue.conf' - -DOMAIN = 'hue' - - -def load_conf(filepath): - """Return the URL for API requests.""" - with open(filepath, 'r') as file_path: - data = json.load(file_path) - ip_add = next(data.keys().__iter__()) - username = data[ip_add]['username'] - url = 'http://' + ip_add + '/api/' + username - return url - - -def setup(hass, config): - """Set up the Hue component.""" - filename = config.get(CONF_FILENAME, PHUE_CONFIG_FILE) - filepath = hass.config.path(filename) - url = load_conf(filepath) - hass.data[DOMAIN] = url - return True diff --git a/custom_components/sensor/hue.py b/custom_components/sensor/hue_sensor.py similarity index 87% rename from custom_components/sensor/hue.py rename to custom_components/sensor/hue_sensor.py index 3553b8a..88c5ea3 100644 --- a/custom_components/sensor/hue.py +++ b/custom_components/sensor/hue_sensor.py @@ -8,21 +8,36 @@ from datetime import timedelta import requests +import json +from homeassistant.const import (CONF_FILENAME) from homeassistant.helpers.entity import Entity from homeassistant.util import Throttle -DOMAIN = 'hue' +DOMAIN = 'hue_sensor' _LOGGER = logging.getLogger(__name__) SCAN_INTERVAL = timedelta(seconds=1) - +PHUE_CONFIG_FILE = 'phue.conf' REQUIREMENTS = ['hue-sensors==1.2'] +def load_conf(filepath): + """Return the URL for API requests.""" + with open(filepath, 'r') as file_path: + data = json.load(file_path) + ip_add = next(data.keys().__iter__()) + username = data[ip_add]['username'] + url = 'http://' + ip_add + '/api/' + username + return url + + def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the Hue sensors.""" import hue_sensors as hs - url = hass.data[DOMAIN] + '/sensors' + + filename = config.get(CONF_FILENAME, PHUE_CONFIG_FILE) + filepath = hass.config.path(filename) + url = load_conf(filepath) + '/sensors' data = HueSensorData(url, hs.parse_hue_api_response) data.update() sensors = []