mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 01:37:08 +00:00
Change line separator to LN (#11662)
This commit is contained in:
parent
56a2c587ad
commit
b0860ce5f0
@ -1,63 +1,63 @@
|
|||||||
"""
|
"""
|
||||||
Support for the Hive devices.
|
Support for the Hive devices.
|
||||||
|
|
||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/binary_sensor.hive/
|
https://home-assistant.io/components/binary_sensor.hive/
|
||||||
"""
|
"""
|
||||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||||
from homeassistant.components.hive import DATA_HIVE
|
from homeassistant.components.hive import DATA_HIVE
|
||||||
|
|
||||||
DEPENDENCIES = ['hive']
|
DEPENDENCIES = ['hive']
|
||||||
|
|
||||||
DEVICETYPE_DEVICE_CLASS = {'motionsensor': 'motion',
|
DEVICETYPE_DEVICE_CLASS = {'motionsensor': 'motion',
|
||||||
'contactsensor': 'opening'}
|
'contactsensor': 'opening'}
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up Hive sensor devices."""
|
"""Set up Hive sensor devices."""
|
||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
session = hass.data.get(DATA_HIVE)
|
session = hass.data.get(DATA_HIVE)
|
||||||
|
|
||||||
add_devices([HiveBinarySensorEntity(session, discovery_info)])
|
add_devices([HiveBinarySensorEntity(session, discovery_info)])
|
||||||
|
|
||||||
|
|
||||||
class HiveBinarySensorEntity(BinarySensorDevice):
|
class HiveBinarySensorEntity(BinarySensorDevice):
|
||||||
"""Representation of a Hive binary sensor."""
|
"""Representation of a Hive binary sensor."""
|
||||||
|
|
||||||
def __init__(self, hivesession, hivedevice):
|
def __init__(self, hivesession, hivedevice):
|
||||||
"""Initialize the hive sensor."""
|
"""Initialize the hive sensor."""
|
||||||
self.node_id = hivedevice["Hive_NodeID"]
|
self.node_id = hivedevice["Hive_NodeID"]
|
||||||
self.node_name = hivedevice["Hive_NodeName"]
|
self.node_name = hivedevice["Hive_NodeName"]
|
||||||
self.device_type = hivedevice["HA_DeviceType"]
|
self.device_type = hivedevice["HA_DeviceType"]
|
||||||
self.node_device_type = hivedevice["Hive_DeviceType"]
|
self.node_device_type = hivedevice["Hive_DeviceType"]
|
||||||
self.session = hivesession
|
self.session = hivesession
|
||||||
self.data_updatesource = '{}.{}'.format(self.device_type,
|
self.data_updatesource = '{}.{}'.format(self.device_type,
|
||||||
self.node_id)
|
self.node_id)
|
||||||
|
|
||||||
self.session.entities.append(self)
|
self.session.entities.append(self)
|
||||||
|
|
||||||
def handle_update(self, updatesource):
|
def handle_update(self, updatesource):
|
||||||
"""Handle the new update request."""
|
"""Handle the new update request."""
|
||||||
if '{}.{}'.format(self.device_type, self.node_id) not in updatesource:
|
if '{}.{}'.format(self.device_type, self.node_id) not in updatesource:
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self):
|
def device_class(self):
|
||||||
"""Return the class of this sensor."""
|
"""Return the class of this sensor."""
|
||||||
return DEVICETYPE_DEVICE_CLASS.get(self.node_device_type)
|
return DEVICETYPE_DEVICE_CLASS.get(self.node_device_type)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the binary sensor."""
|
"""Return the name of the binary sensor."""
|
||||||
return self.node_name
|
return self.node_name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if the binary sensor is on."""
|
"""Return true if the binary sensor is on."""
|
||||||
return self.session.sensor.get_state(self.node_id,
|
return self.session.sensor.get_state(self.node_id,
|
||||||
self.node_device_type)
|
self.node_device_type)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update all Node data frome Hive."""
|
"""Update all Node data frome Hive."""
|
||||||
self.session.core.update_data(self.node_id)
|
self.session.core.update_data(self.node_id)
|
||||||
|
@ -1,178 +1,178 @@
|
|||||||
"""
|
"""
|
||||||
Support for the Hive devices.
|
Support for the Hive devices.
|
||||||
|
|
||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/climate.hive/
|
https://home-assistant.io/components/climate.hive/
|
||||||
"""
|
"""
|
||||||
from homeassistant.components.climate import (
|
from homeassistant.components.climate import (
|
||||||
ClimateDevice, STATE_AUTO, STATE_HEAT, STATE_OFF, STATE_ON,
|
ClimateDevice, STATE_AUTO, STATE_HEAT, STATE_OFF, STATE_ON,
|
||||||
SUPPORT_AUX_HEAT, SUPPORT_TARGET_TEMPERATURE, SUPPORT_OPERATION_MODE)
|
SUPPORT_AUX_HEAT, SUPPORT_TARGET_TEMPERATURE, SUPPORT_OPERATION_MODE)
|
||||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
||||||
from homeassistant.components.hive import DATA_HIVE
|
from homeassistant.components.hive import DATA_HIVE
|
||||||
|
|
||||||
DEPENDENCIES = ['hive']
|
DEPENDENCIES = ['hive']
|
||||||
HIVE_TO_HASS_STATE = {'SCHEDULE': STATE_AUTO, 'MANUAL': STATE_HEAT,
|
HIVE_TO_HASS_STATE = {'SCHEDULE': STATE_AUTO, 'MANUAL': STATE_HEAT,
|
||||||
'ON': STATE_ON, 'OFF': STATE_OFF}
|
'ON': STATE_ON, 'OFF': STATE_OFF}
|
||||||
HASS_TO_HIVE_STATE = {STATE_AUTO: 'SCHEDULE', STATE_HEAT: 'MANUAL',
|
HASS_TO_HIVE_STATE = {STATE_AUTO: 'SCHEDULE', STATE_HEAT: 'MANUAL',
|
||||||
STATE_ON: 'ON', STATE_OFF: 'OFF'}
|
STATE_ON: 'ON', STATE_OFF: 'OFF'}
|
||||||
|
|
||||||
SUPPORT_FLAGS = (SUPPORT_TARGET_TEMPERATURE |
|
SUPPORT_FLAGS = (SUPPORT_TARGET_TEMPERATURE |
|
||||||
SUPPORT_OPERATION_MODE |
|
SUPPORT_OPERATION_MODE |
|
||||||
SUPPORT_AUX_HEAT)
|
SUPPORT_AUX_HEAT)
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up Hive climate devices."""
|
"""Set up Hive climate devices."""
|
||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
session = hass.data.get(DATA_HIVE)
|
session = hass.data.get(DATA_HIVE)
|
||||||
|
|
||||||
add_devices([HiveClimateEntity(session, discovery_info)])
|
add_devices([HiveClimateEntity(session, discovery_info)])
|
||||||
|
|
||||||
|
|
||||||
class HiveClimateEntity(ClimateDevice):
|
class HiveClimateEntity(ClimateDevice):
|
||||||
"""Hive Climate Device."""
|
"""Hive Climate Device."""
|
||||||
|
|
||||||
def __init__(self, hivesession, hivedevice):
|
def __init__(self, hivesession, hivedevice):
|
||||||
"""Initialize the Climate device."""
|
"""Initialize the Climate device."""
|
||||||
self.node_id = hivedevice["Hive_NodeID"]
|
self.node_id = hivedevice["Hive_NodeID"]
|
||||||
self.node_name = hivedevice["Hive_NodeName"]
|
self.node_name = hivedevice["Hive_NodeName"]
|
||||||
self.device_type = hivedevice["HA_DeviceType"]
|
self.device_type = hivedevice["HA_DeviceType"]
|
||||||
self.session = hivesession
|
self.session = hivesession
|
||||||
self.data_updatesource = '{}.{}'.format(self.device_type,
|
self.data_updatesource = '{}.{}'.format(self.device_type,
|
||||||
self.node_id)
|
self.node_id)
|
||||||
|
|
||||||
if self.device_type == "Heating":
|
if self.device_type == "Heating":
|
||||||
self.modes = [STATE_AUTO, STATE_HEAT, STATE_OFF]
|
self.modes = [STATE_AUTO, STATE_HEAT, STATE_OFF]
|
||||||
elif self.device_type == "HotWater":
|
elif self.device_type == "HotWater":
|
||||||
self.modes = [STATE_AUTO, STATE_ON, STATE_OFF]
|
self.modes = [STATE_AUTO, STATE_ON, STATE_OFF]
|
||||||
|
|
||||||
self.session.entities.append(self)
|
self.session.entities.append(self)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
"""Return the list of supported features."""
|
"""Return the list of supported features."""
|
||||||
return SUPPORT_FLAGS
|
return SUPPORT_FLAGS
|
||||||
|
|
||||||
def handle_update(self, updatesource):
|
def handle_update(self, updatesource):
|
||||||
"""Handle the new update request."""
|
"""Handle the new update request."""
|
||||||
if '{}.{}'.format(self.device_type, self.node_id) not in updatesource:
|
if '{}.{}'.format(self.device_type, self.node_id) not in updatesource:
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the Climate device."""
|
"""Return the name of the Climate device."""
|
||||||
friendly_name = "Climate Device"
|
friendly_name = "Climate Device"
|
||||||
if self.device_type == "Heating":
|
if self.device_type == "Heating":
|
||||||
friendly_name = "Heating"
|
friendly_name = "Heating"
|
||||||
if self.node_name is not None:
|
if self.node_name is not None:
|
||||||
friendly_name = '{} {}'.format(self.node_name, friendly_name)
|
friendly_name = '{} {}'.format(self.node_name, friendly_name)
|
||||||
elif self.device_type == "HotWater":
|
elif self.device_type == "HotWater":
|
||||||
friendly_name = "Hot Water"
|
friendly_name = "Hot Water"
|
||||||
return friendly_name
|
return friendly_name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def temperature_unit(self):
|
def temperature_unit(self):
|
||||||
"""Return the unit of measurement."""
|
"""Return the unit of measurement."""
|
||||||
return TEMP_CELSIUS
|
return TEMP_CELSIUS
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_temperature(self):
|
def current_temperature(self):
|
||||||
"""Return the current temperature."""
|
"""Return the current temperature."""
|
||||||
if self.device_type == "Heating":
|
if self.device_type == "Heating":
|
||||||
return self.session.heating.current_temperature(self.node_id)
|
return self.session.heating.current_temperature(self.node_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature(self):
|
def target_temperature(self):
|
||||||
"""Return the target temperature."""
|
"""Return the target temperature."""
|
||||||
if self.device_type == "Heating":
|
if self.device_type == "Heating":
|
||||||
return self.session.heating.get_target_temperature(self.node_id)
|
return self.session.heating.get_target_temperature(self.node_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def min_temp(self):
|
def min_temp(self):
|
||||||
"""Return minimum temperature."""
|
"""Return minimum temperature."""
|
||||||
if self.device_type == "Heating":
|
if self.device_type == "Heating":
|
||||||
return self.session.heating.min_temperature(self.node_id)
|
return self.session.heating.min_temperature(self.node_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def max_temp(self):
|
def max_temp(self):
|
||||||
"""Return the maximum temperature."""
|
"""Return the maximum temperature."""
|
||||||
if self.device_type == "Heating":
|
if self.device_type == "Heating":
|
||||||
return self.session.heating.max_temperature(self.node_id)
|
return self.session.heating.max_temperature(self.node_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def operation_list(self):
|
def operation_list(self):
|
||||||
"""List of the operation modes."""
|
"""List of the operation modes."""
|
||||||
return self.modes
|
return self.modes
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_operation(self):
|
def current_operation(self):
|
||||||
"""Return current mode."""
|
"""Return current mode."""
|
||||||
if self.device_type == "Heating":
|
if self.device_type == "Heating":
|
||||||
currentmode = self.session.heating.get_mode(self.node_id)
|
currentmode = self.session.heating.get_mode(self.node_id)
|
||||||
elif self.device_type == "HotWater":
|
elif self.device_type == "HotWater":
|
||||||
currentmode = self.session.hotwater.get_mode(self.node_id)
|
currentmode = self.session.hotwater.get_mode(self.node_id)
|
||||||
return HIVE_TO_HASS_STATE.get(currentmode)
|
return HIVE_TO_HASS_STATE.get(currentmode)
|
||||||
|
|
||||||
def set_operation_mode(self, operation_mode):
|
def set_operation_mode(self, operation_mode):
|
||||||
"""Set new Heating mode."""
|
"""Set new Heating mode."""
|
||||||
new_mode = HASS_TO_HIVE_STATE.get(operation_mode)
|
new_mode = HASS_TO_HIVE_STATE.get(operation_mode)
|
||||||
if self.device_type == "Heating":
|
if self.device_type == "Heating":
|
||||||
self.session.heating.set_mode(self.node_id, new_mode)
|
self.session.heating.set_mode(self.node_id, new_mode)
|
||||||
elif self.device_type == "HotWater":
|
elif self.device_type == "HotWater":
|
||||||
self.session.hotwater.set_mode(self.node_id, new_mode)
|
self.session.hotwater.set_mode(self.node_id, new_mode)
|
||||||
|
|
||||||
for entity in self.session.entities:
|
for entity in self.session.entities:
|
||||||
entity.handle_update(self.data_updatesource)
|
entity.handle_update(self.data_updatesource)
|
||||||
|
|
||||||
def set_temperature(self, **kwargs):
|
def set_temperature(self, **kwargs):
|
||||||
"""Set new target temperature."""
|
"""Set new target temperature."""
|
||||||
new_temperature = kwargs.get(ATTR_TEMPERATURE)
|
new_temperature = kwargs.get(ATTR_TEMPERATURE)
|
||||||
if new_temperature is not None:
|
if new_temperature is not None:
|
||||||
if self.device_type == "Heating":
|
if self.device_type == "Heating":
|
||||||
self.session.heating.set_target_temperature(self.node_id,
|
self.session.heating.set_target_temperature(self.node_id,
|
||||||
new_temperature)
|
new_temperature)
|
||||||
|
|
||||||
for entity in self.session.entities:
|
for entity in self.session.entities:
|
||||||
entity.handle_update(self.data_updatesource)
|
entity.handle_update(self.data_updatesource)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_aux_heat_on(self):
|
def is_aux_heat_on(self):
|
||||||
"""Return true if auxiliary heater is on."""
|
"""Return true if auxiliary heater is on."""
|
||||||
boost_status = None
|
boost_status = None
|
||||||
if self.device_type == "Heating":
|
if self.device_type == "Heating":
|
||||||
boost_status = self.session.heating.get_boost(self.node_id)
|
boost_status = self.session.heating.get_boost(self.node_id)
|
||||||
elif self.device_type == "HotWater":
|
elif self.device_type == "HotWater":
|
||||||
boost_status = self.session.hotwater.get_boost(self.node_id)
|
boost_status = self.session.hotwater.get_boost(self.node_id)
|
||||||
return boost_status == "ON"
|
return boost_status == "ON"
|
||||||
|
|
||||||
def turn_aux_heat_on(self):
|
def turn_aux_heat_on(self):
|
||||||
"""Turn auxiliary heater on."""
|
"""Turn auxiliary heater on."""
|
||||||
target_boost_time = 30
|
target_boost_time = 30
|
||||||
if self.device_type == "Heating":
|
if self.device_type == "Heating":
|
||||||
curtemp = self.session.heating.current_temperature(self.node_id)
|
curtemp = self.session.heating.current_temperature(self.node_id)
|
||||||
curtemp = round(curtemp * 2) / 2
|
curtemp = round(curtemp * 2) / 2
|
||||||
target_boost_temperature = curtemp + 0.5
|
target_boost_temperature = curtemp + 0.5
|
||||||
self.session.heating.turn_boost_on(self.node_id,
|
self.session.heating.turn_boost_on(self.node_id,
|
||||||
target_boost_time,
|
target_boost_time,
|
||||||
target_boost_temperature)
|
target_boost_temperature)
|
||||||
elif self.device_type == "HotWater":
|
elif self.device_type == "HotWater":
|
||||||
self.session.hotwater.turn_boost_on(self.node_id,
|
self.session.hotwater.turn_boost_on(self.node_id,
|
||||||
target_boost_time)
|
target_boost_time)
|
||||||
|
|
||||||
for entity in self.session.entities:
|
for entity in self.session.entities:
|
||||||
entity.handle_update(self.data_updatesource)
|
entity.handle_update(self.data_updatesource)
|
||||||
|
|
||||||
def turn_aux_heat_off(self):
|
def turn_aux_heat_off(self):
|
||||||
"""Turn auxiliary heater off."""
|
"""Turn auxiliary heater off."""
|
||||||
if self.device_type == "Heating":
|
if self.device_type == "Heating":
|
||||||
self.session.heating.turn_boost_off(self.node_id)
|
self.session.heating.turn_boost_off(self.node_id)
|
||||||
elif self.device_type == "HotWater":
|
elif self.device_type == "HotWater":
|
||||||
self.session.hotwater.turn_boost_off(self.node_id)
|
self.session.hotwater.turn_boost_off(self.node_id)
|
||||||
|
|
||||||
for entity in self.session.entities:
|
for entity in self.session.entities:
|
||||||
entity.handle_update(self.data_updatesource)
|
entity.handle_update(self.data_updatesource)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update all Node data frome Hive."""
|
"""Update all Node data frome Hive."""
|
||||||
self.session.core.update_data(self.node_id)
|
self.session.core.update_data(self.node_id)
|
||||||
|
@ -1,80 +1,80 @@
|
|||||||
"""
|
"""
|
||||||
Support for the Hive devices.
|
Support for the Hive devices.
|
||||||
|
|
||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/hive/
|
https://home-assistant.io/components/hive/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import (CONF_PASSWORD, CONF_SCAN_INTERVAL,
|
from homeassistant.const import (CONF_PASSWORD, CONF_SCAN_INTERVAL,
|
||||||
CONF_USERNAME)
|
CONF_USERNAME)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.discovery import load_platform
|
from homeassistant.helpers.discovery import load_platform
|
||||||
|
|
||||||
REQUIREMENTS = ['pyhiveapi==0.2.10']
|
REQUIREMENTS = ['pyhiveapi==0.2.10']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
DOMAIN = 'hive'
|
DOMAIN = 'hive'
|
||||||
DATA_HIVE = 'data_hive'
|
DATA_HIVE = 'data_hive'
|
||||||
DEVICETYPES = {
|
DEVICETYPES = {
|
||||||
'binary_sensor': 'device_list_binary_sensor',
|
'binary_sensor': 'device_list_binary_sensor',
|
||||||
'climate': 'device_list_climate',
|
'climate': 'device_list_climate',
|
||||||
'light': 'device_list_light',
|
'light': 'device_list_light',
|
||||||
'switch': 'device_list_plug',
|
'switch': 'device_list_plug',
|
||||||
'sensor': 'device_list_sensor',
|
'sensor': 'device_list_sensor',
|
||||||
}
|
}
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
DOMAIN: vol.Schema({
|
DOMAIN: vol.Schema({
|
||||||
vol.Required(CONF_PASSWORD): cv.string,
|
vol.Required(CONF_PASSWORD): cv.string,
|
||||||
vol.Required(CONF_USERNAME): cv.string,
|
vol.Required(CONF_USERNAME): cv.string,
|
||||||
vol.Optional(CONF_SCAN_INTERVAL, default=2): cv.positive_int,
|
vol.Optional(CONF_SCAN_INTERVAL, default=2): cv.positive_int,
|
||||||
})
|
})
|
||||||
}, extra=vol.ALLOW_EXTRA)
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
|
|
||||||
class HiveSession:
|
class HiveSession:
|
||||||
"""Initiate Hive Session Class."""
|
"""Initiate Hive Session Class."""
|
||||||
|
|
||||||
entities = []
|
entities = []
|
||||||
core = None
|
core = None
|
||||||
heating = None
|
heating = None
|
||||||
hotwater = None
|
hotwater = None
|
||||||
light = None
|
light = None
|
||||||
sensor = None
|
sensor = None
|
||||||
switch = None
|
switch = None
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
"""Set up the Hive Component."""
|
"""Set up the Hive Component."""
|
||||||
from pyhiveapi import Pyhiveapi
|
from pyhiveapi import Pyhiveapi
|
||||||
|
|
||||||
session = HiveSession()
|
session = HiveSession()
|
||||||
session.core = Pyhiveapi()
|
session.core = Pyhiveapi()
|
||||||
|
|
||||||
username = config[DOMAIN][CONF_USERNAME]
|
username = config[DOMAIN][CONF_USERNAME]
|
||||||
password = config[DOMAIN][CONF_PASSWORD]
|
password = config[DOMAIN][CONF_PASSWORD]
|
||||||
update_interval = config[DOMAIN][CONF_SCAN_INTERVAL]
|
update_interval = config[DOMAIN][CONF_SCAN_INTERVAL]
|
||||||
|
|
||||||
devicelist = session.core.initialise_api(username,
|
devicelist = session.core.initialise_api(username,
|
||||||
password,
|
password,
|
||||||
update_interval)
|
update_interval)
|
||||||
|
|
||||||
if devicelist is None:
|
if devicelist is None:
|
||||||
_LOGGER.error("Hive API initialization failed")
|
_LOGGER.error("Hive API initialization failed")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
session.sensor = Pyhiveapi.Sensor()
|
session.sensor = Pyhiveapi.Sensor()
|
||||||
session.heating = Pyhiveapi.Heating()
|
session.heating = Pyhiveapi.Heating()
|
||||||
session.hotwater = Pyhiveapi.Hotwater()
|
session.hotwater = Pyhiveapi.Hotwater()
|
||||||
session.light = Pyhiveapi.Light()
|
session.light = Pyhiveapi.Light()
|
||||||
session.switch = Pyhiveapi.Switch()
|
session.switch = Pyhiveapi.Switch()
|
||||||
hass.data[DATA_HIVE] = session
|
hass.data[DATA_HIVE] = session
|
||||||
|
|
||||||
for ha_type, hive_type in DEVICETYPES.items():
|
for ha_type, hive_type in DEVICETYPES.items():
|
||||||
for key, devices in devicelist.items():
|
for key, devices in devicelist.items():
|
||||||
if key == hive_type:
|
if key == hive_type:
|
||||||
for hivedevice in devices:
|
for hivedevice in devices:
|
||||||
load_platform(hass, ha_type, DOMAIN, hivedevice, config)
|
load_platform(hass, ha_type, DOMAIN, hivedevice, config)
|
||||||
return True
|
return True
|
||||||
|
@ -1,141 +1,141 @@
|
|||||||
"""
|
"""
|
||||||
Support for the Hive devices.
|
Support for the Hive devices.
|
||||||
|
|
||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/light.hive/
|
https://home-assistant.io/components/light.hive/
|
||||||
"""
|
"""
|
||||||
import colorsys
|
import colorsys
|
||||||
from homeassistant.components.hive import DATA_HIVE
|
from homeassistant.components.hive import DATA_HIVE
|
||||||
from homeassistant.components.light import (ATTR_BRIGHTNESS, ATTR_COLOR_TEMP,
|
from homeassistant.components.light import (ATTR_BRIGHTNESS, ATTR_COLOR_TEMP,
|
||||||
ATTR_RGB_COLOR,
|
ATTR_RGB_COLOR,
|
||||||
SUPPORT_BRIGHTNESS,
|
SUPPORT_BRIGHTNESS,
|
||||||
SUPPORT_COLOR_TEMP,
|
SUPPORT_COLOR_TEMP,
|
||||||
SUPPORT_RGB_COLOR, Light)
|
SUPPORT_RGB_COLOR, Light)
|
||||||
|
|
||||||
DEPENDENCIES = ['hive']
|
DEPENDENCIES = ['hive']
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up Hive light devices."""
|
"""Set up Hive light devices."""
|
||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
session = hass.data.get(DATA_HIVE)
|
session = hass.data.get(DATA_HIVE)
|
||||||
|
|
||||||
add_devices([HiveDeviceLight(session, discovery_info)])
|
add_devices([HiveDeviceLight(session, discovery_info)])
|
||||||
|
|
||||||
|
|
||||||
class HiveDeviceLight(Light):
|
class HiveDeviceLight(Light):
|
||||||
"""Hive Active Light Device."""
|
"""Hive Active Light Device."""
|
||||||
|
|
||||||
def __init__(self, hivesession, hivedevice):
|
def __init__(self, hivesession, hivedevice):
|
||||||
"""Initialize the Light device."""
|
"""Initialize the Light device."""
|
||||||
self.node_id = hivedevice["Hive_NodeID"]
|
self.node_id = hivedevice["Hive_NodeID"]
|
||||||
self.node_name = hivedevice["Hive_NodeName"]
|
self.node_name = hivedevice["Hive_NodeName"]
|
||||||
self.device_type = hivedevice["HA_DeviceType"]
|
self.device_type = hivedevice["HA_DeviceType"]
|
||||||
self.light_device_type = hivedevice["Hive_Light_DeviceType"]
|
self.light_device_type = hivedevice["Hive_Light_DeviceType"]
|
||||||
self.session = hivesession
|
self.session = hivesession
|
||||||
self.data_updatesource = '{}.{}'.format(self.device_type,
|
self.data_updatesource = '{}.{}'.format(self.device_type,
|
||||||
self.node_id)
|
self.node_id)
|
||||||
self.session.entities.append(self)
|
self.session.entities.append(self)
|
||||||
|
|
||||||
def handle_update(self, updatesource):
|
def handle_update(self, updatesource):
|
||||||
"""Handle the new update request."""
|
"""Handle the new update request."""
|
||||||
if '{}.{}'.format(self.device_type, self.node_id) not in updatesource:
|
if '{}.{}'.format(self.device_type, self.node_id) not in updatesource:
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the display name of this light."""
|
"""Return the display name of this light."""
|
||||||
return self.node_name
|
return self.node_name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def brightness(self):
|
def brightness(self):
|
||||||
"""Brightness of the light (an integer in the range 1-255)."""
|
"""Brightness of the light (an integer in the range 1-255)."""
|
||||||
return self.session.light.get_brightness(self.node_id)
|
return self.session.light.get_brightness(self.node_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def min_mireds(self):
|
def min_mireds(self):
|
||||||
"""Return the coldest color_temp that this light supports."""
|
"""Return the coldest color_temp that this light supports."""
|
||||||
if self.light_device_type == "tuneablelight" \
|
if self.light_device_type == "tuneablelight" \
|
||||||
or self.light_device_type == "colourtuneablelight":
|
or self.light_device_type == "colourtuneablelight":
|
||||||
return self.session.light.get_min_color_temp(self.node_id)
|
return self.session.light.get_min_color_temp(self.node_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def max_mireds(self):
|
def max_mireds(self):
|
||||||
"""Return the warmest color_temp that this light supports."""
|
"""Return the warmest color_temp that this light supports."""
|
||||||
if self.light_device_type == "tuneablelight" \
|
if self.light_device_type == "tuneablelight" \
|
||||||
or self.light_device_type == "colourtuneablelight":
|
or self.light_device_type == "colourtuneablelight":
|
||||||
return self.session.light.get_max_color_temp(self.node_id)
|
return self.session.light.get_max_color_temp(self.node_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def color_temp(self):
|
def color_temp(self):
|
||||||
"""Return the CT color value in mireds."""
|
"""Return the CT color value in mireds."""
|
||||||
if self.light_device_type == "tuneablelight" \
|
if self.light_device_type == "tuneablelight" \
|
||||||
or self.light_device_type == "colourtuneablelight":
|
or self.light_device_type == "colourtuneablelight":
|
||||||
return self.session.light.get_color_temp(self.node_id)
|
return self.session.light.get_color_temp(self.node_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rgb_color(self) -> tuple:
|
def rgb_color(self) -> tuple:
|
||||||
"""Return the RBG color value."""
|
"""Return the RBG color value."""
|
||||||
if self.light_device_type == "colourtuneablelight":
|
if self.light_device_type == "colourtuneablelight":
|
||||||
return self.session.light.get_color(self.node_id)
|
return self.session.light.get_color(self.node_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if light is on."""
|
"""Return true if light is on."""
|
||||||
return self.session.light.get_state(self.node_id)
|
return self.session.light.get_state(self.node_id)
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
"""Instruct the light to turn on."""
|
"""Instruct the light to turn on."""
|
||||||
new_brightness = None
|
new_brightness = None
|
||||||
new_color_temp = None
|
new_color_temp = None
|
||||||
new_color = None
|
new_color = None
|
||||||
if ATTR_BRIGHTNESS in kwargs:
|
if ATTR_BRIGHTNESS in kwargs:
|
||||||
tmp_new_brightness = kwargs.get(ATTR_BRIGHTNESS)
|
tmp_new_brightness = kwargs.get(ATTR_BRIGHTNESS)
|
||||||
percentage_brightness = ((tmp_new_brightness / 255) * 100)
|
percentage_brightness = ((tmp_new_brightness / 255) * 100)
|
||||||
new_brightness = int(round(percentage_brightness / 5.0) * 5.0)
|
new_brightness = int(round(percentage_brightness / 5.0) * 5.0)
|
||||||
if new_brightness == 0:
|
if new_brightness == 0:
|
||||||
new_brightness = 5
|
new_brightness = 5
|
||||||
if ATTR_COLOR_TEMP in kwargs:
|
if ATTR_COLOR_TEMP in kwargs:
|
||||||
tmp_new_color_temp = kwargs.get(ATTR_COLOR_TEMP)
|
tmp_new_color_temp = kwargs.get(ATTR_COLOR_TEMP)
|
||||||
new_color_temp = round(1000000 / tmp_new_color_temp)
|
new_color_temp = round(1000000 / tmp_new_color_temp)
|
||||||
if ATTR_RGB_COLOR in kwargs:
|
if ATTR_RGB_COLOR in kwargs:
|
||||||
get_new_color = kwargs.get(ATTR_RGB_COLOR)
|
get_new_color = kwargs.get(ATTR_RGB_COLOR)
|
||||||
tmp_new_color = colorsys.rgb_to_hsv(get_new_color[0],
|
tmp_new_color = colorsys.rgb_to_hsv(get_new_color[0],
|
||||||
get_new_color[1],
|
get_new_color[1],
|
||||||
get_new_color[2])
|
get_new_color[2])
|
||||||
hue = int(round(tmp_new_color[0] * 360))
|
hue = int(round(tmp_new_color[0] * 360))
|
||||||
saturation = int(round(tmp_new_color[1] * 100))
|
saturation = int(round(tmp_new_color[1] * 100))
|
||||||
value = int(round((tmp_new_color[2] / 255) * 100))
|
value = int(round((tmp_new_color[2] / 255) * 100))
|
||||||
new_color = (hue, saturation, value)
|
new_color = (hue, saturation, value)
|
||||||
|
|
||||||
self.session.light.turn_on(self.node_id, self.light_device_type,
|
self.session.light.turn_on(self.node_id, self.light_device_type,
|
||||||
new_brightness, new_color_temp,
|
new_brightness, new_color_temp,
|
||||||
new_color)
|
new_color)
|
||||||
|
|
||||||
for entity in self.session.entities:
|
for entity in self.session.entities:
|
||||||
entity.handle_update(self.data_updatesource)
|
entity.handle_update(self.data_updatesource)
|
||||||
|
|
||||||
def turn_off(self):
|
def turn_off(self):
|
||||||
"""Instruct the light to turn off."""
|
"""Instruct the light to turn off."""
|
||||||
self.session.light.turn_off(self.node_id)
|
self.session.light.turn_off(self.node_id)
|
||||||
for entity in self.session.entities:
|
for entity in self.session.entities:
|
||||||
entity.handle_update(self.data_updatesource)
|
entity.handle_update(self.data_updatesource)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
supported_features = None
|
supported_features = None
|
||||||
if self.light_device_type == "warmwhitelight":
|
if self.light_device_type == "warmwhitelight":
|
||||||
supported_features = SUPPORT_BRIGHTNESS
|
supported_features = SUPPORT_BRIGHTNESS
|
||||||
elif self.light_device_type == "tuneablelight":
|
elif self.light_device_type == "tuneablelight":
|
||||||
supported_features = (SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP)
|
supported_features = (SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP)
|
||||||
elif self.light_device_type == "colourtuneablelight":
|
elif self.light_device_type == "colourtuneablelight":
|
||||||
supported_features = (
|
supported_features = (
|
||||||
SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_RGB_COLOR)
|
SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_RGB_COLOR)
|
||||||
|
|
||||||
return supported_features
|
return supported_features
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update all Node data frome Hive."""
|
"""Update all Node data frome Hive."""
|
||||||
self.session.core.update_data(self.node_id)
|
self.session.core.update_data(self.node_id)
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
"""
|
"""
|
||||||
Provides a map panel for showing device locations.
|
Provides a map panel for showing device locations.
|
||||||
|
|
||||||
For more details about this component, please refer to the documentation at
|
For more details about this component, please refer to the documentation at
|
||||||
https://home-assistant.io/components/map/
|
https://home-assistant.io/components/map/
|
||||||
"""
|
"""
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
DOMAIN = 'map'
|
DOMAIN = 'map'
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_setup(hass, config):
|
def async_setup(hass, config):
|
||||||
"""Register the built-in map panel."""
|
"""Register the built-in map panel."""
|
||||||
yield from hass.components.frontend.async_register_built_in_panel(
|
yield from hass.components.frontend.async_register_built_in_panel(
|
||||||
'map', 'map', 'mdi:account-location')
|
'map', 'map', 'mdi:account-location')
|
||||||
return True
|
return True
|
||||||
|
@ -1,70 +1,70 @@
|
|||||||
"""
|
"""
|
||||||
Prowl notification service.
|
Prowl notification service.
|
||||||
|
|
||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/notify.prowl/
|
https://home-assistant.io/components/notify.prowl/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
import async_timeout
|
import async_timeout
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.notify import (
|
from homeassistant.components.notify import (
|
||||||
ATTR_TITLE, ATTR_TITLE_DEFAULT, ATTR_DATA, PLATFORM_SCHEMA,
|
ATTR_TITLE, ATTR_TITLE_DEFAULT, ATTR_DATA, PLATFORM_SCHEMA,
|
||||||
BaseNotificationService)
|
BaseNotificationService)
|
||||||
from homeassistant.const import CONF_API_KEY
|
from homeassistant.const import CONF_API_KEY
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
_RESOURCE = 'https://api.prowlapp.com/publicapi/'
|
_RESOURCE = 'https://api.prowlapp.com/publicapi/'
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_API_KEY): cv.string,
|
vol.Required(CONF_API_KEY): cv.string,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_get_service(hass, config, discovery_info=None):
|
def async_get_service(hass, config, discovery_info=None):
|
||||||
"""Get the Prowl notification service."""
|
"""Get the Prowl notification service."""
|
||||||
return ProwlNotificationService(hass, config[CONF_API_KEY])
|
return ProwlNotificationService(hass, config[CONF_API_KEY])
|
||||||
|
|
||||||
|
|
||||||
class ProwlNotificationService(BaseNotificationService):
|
class ProwlNotificationService(BaseNotificationService):
|
||||||
"""Implement the notification service for Prowl."""
|
"""Implement the notification service for Prowl."""
|
||||||
|
|
||||||
def __init__(self, hass, api_key):
|
def __init__(self, hass, api_key):
|
||||||
"""Initialize the service."""
|
"""Initialize the service."""
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
self._api_key = api_key
|
self._api_key = api_key
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_send_message(self, message, **kwargs):
|
def async_send_message(self, message, **kwargs):
|
||||||
"""Send the message to the user."""
|
"""Send the message to the user."""
|
||||||
response = None
|
response = None
|
||||||
session = None
|
session = None
|
||||||
url = '{}{}'.format(_RESOURCE, 'add')
|
url = '{}{}'.format(_RESOURCE, 'add')
|
||||||
data = kwargs.get(ATTR_DATA)
|
data = kwargs.get(ATTR_DATA)
|
||||||
payload = {
|
payload = {
|
||||||
'apikey': self._api_key,
|
'apikey': self._api_key,
|
||||||
'application': 'Home-Assistant',
|
'application': 'Home-Assistant',
|
||||||
'event': kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT),
|
'event': kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT),
|
||||||
'description': message,
|
'description': message,
|
||||||
'priority': data['priority'] if data and 'priority' in data else 0
|
'priority': data['priority'] if data and 'priority' in data else 0
|
||||||
}
|
}
|
||||||
|
|
||||||
_LOGGER.debug("Attempting call Prowl service at %s", url)
|
_LOGGER.debug("Attempting call Prowl service at %s", url)
|
||||||
session = async_get_clientsession(self._hass)
|
session = async_get_clientsession(self._hass)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with async_timeout.timeout(10, loop=self._hass.loop):
|
with async_timeout.timeout(10, loop=self._hass.loop):
|
||||||
response = yield from session.post(url, data=payload)
|
response = yield from session.post(url, data=payload)
|
||||||
result = yield from response.text()
|
result = yield from response.text()
|
||||||
|
|
||||||
if response.status != 200 or 'error' in result:
|
if response.status != 200 or 'error' in result:
|
||||||
_LOGGER.error("Prowl service returned http "
|
_LOGGER.error("Prowl service returned http "
|
||||||
"status %d, response %s",
|
"status %d, response %s",
|
||||||
response.status, result)
|
response.status, result)
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
_LOGGER.error("Timeout accessing Prowl at %s", url)
|
_LOGGER.error("Timeout accessing Prowl at %s", url)
|
||||||
|
@ -1,52 +1,52 @@
|
|||||||
"""
|
"""
|
||||||
Support for the Hive devices.
|
Support for the Hive devices.
|
||||||
|
|
||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/sensor.hive/
|
https://home-assistant.io/components/sensor.hive/
|
||||||
"""
|
"""
|
||||||
from homeassistant.components.hive import DATA_HIVE
|
from homeassistant.components.hive import DATA_HIVE
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
DEPENDENCIES = ['hive']
|
DEPENDENCIES = ['hive']
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up Hive sensor devices."""
|
"""Set up Hive sensor devices."""
|
||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
session = hass.data.get(DATA_HIVE)
|
session = hass.data.get(DATA_HIVE)
|
||||||
|
|
||||||
if discovery_info["HA_DeviceType"] == "Hub_OnlineStatus":
|
if discovery_info["HA_DeviceType"] == "Hub_OnlineStatus":
|
||||||
add_devices([HiveSensorEntity(session, discovery_info)])
|
add_devices([HiveSensorEntity(session, discovery_info)])
|
||||||
|
|
||||||
|
|
||||||
class HiveSensorEntity(Entity):
|
class HiveSensorEntity(Entity):
|
||||||
"""Hive Sensor Entity."""
|
"""Hive Sensor Entity."""
|
||||||
|
|
||||||
def __init__(self, hivesession, hivedevice):
|
def __init__(self, hivesession, hivedevice):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self.node_id = hivedevice["Hive_NodeID"]
|
self.node_id = hivedevice["Hive_NodeID"]
|
||||||
self.device_type = hivedevice["HA_DeviceType"]
|
self.device_type = hivedevice["HA_DeviceType"]
|
||||||
self.session = hivesession
|
self.session = hivesession
|
||||||
self.data_updatesource = '{}.{}'.format(self.device_type,
|
self.data_updatesource = '{}.{}'.format(self.device_type,
|
||||||
self.node_id)
|
self.node_id)
|
||||||
self.session.entities.append(self)
|
self.session.entities.append(self)
|
||||||
|
|
||||||
def handle_update(self, updatesource):
|
def handle_update(self, updatesource):
|
||||||
"""Handle the new update request."""
|
"""Handle the new update request."""
|
||||||
if '{}.{}'.format(self.device_type, self.node_id) not in updatesource:
|
if '{}.{}'.format(self.device_type, self.node_id) not in updatesource:
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return "Hive hub status"
|
return "Hive hub status"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self.session.sensor.hub_online_status(self.node_id)
|
return self.session.sensor.hub_online_status(self.node_id)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update all Node data frome Hive."""
|
"""Update all Node data frome Hive."""
|
||||||
self.session.core.update_data(self.node_id)
|
self.session.core.update_data(self.node_id)
|
||||||
|
@ -1,69 +1,69 @@
|
|||||||
"""
|
"""
|
||||||
Support for the Hive devices.
|
Support for the Hive devices.
|
||||||
|
|
||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/switch.hive/
|
https://home-assistant.io/components/switch.hive/
|
||||||
"""
|
"""
|
||||||
from homeassistant.components.switch import SwitchDevice
|
from homeassistant.components.switch import SwitchDevice
|
||||||
from homeassistant.components.hive import DATA_HIVE
|
from homeassistant.components.hive import DATA_HIVE
|
||||||
|
|
||||||
DEPENDENCIES = ['hive']
|
DEPENDENCIES = ['hive']
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up Hive switches."""
|
"""Set up Hive switches."""
|
||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
session = hass.data.get(DATA_HIVE)
|
session = hass.data.get(DATA_HIVE)
|
||||||
|
|
||||||
add_devices([HiveDevicePlug(session, discovery_info)])
|
add_devices([HiveDevicePlug(session, discovery_info)])
|
||||||
|
|
||||||
|
|
||||||
class HiveDevicePlug(SwitchDevice):
|
class HiveDevicePlug(SwitchDevice):
|
||||||
"""Hive Active Plug."""
|
"""Hive Active Plug."""
|
||||||
|
|
||||||
def __init__(self, hivesession, hivedevice):
|
def __init__(self, hivesession, hivedevice):
|
||||||
"""Initialize the Switch device."""
|
"""Initialize the Switch device."""
|
||||||
self.node_id = hivedevice["Hive_NodeID"]
|
self.node_id = hivedevice["Hive_NodeID"]
|
||||||
self.node_name = hivedevice["Hive_NodeName"]
|
self.node_name = hivedevice["Hive_NodeName"]
|
||||||
self.device_type = hivedevice["HA_DeviceType"]
|
self.device_type = hivedevice["HA_DeviceType"]
|
||||||
self.session = hivesession
|
self.session = hivesession
|
||||||
self.data_updatesource = '{}.{}'.format(self.device_type,
|
self.data_updatesource = '{}.{}'.format(self.device_type,
|
||||||
self.node_id)
|
self.node_id)
|
||||||
self.session.entities.append(self)
|
self.session.entities.append(self)
|
||||||
|
|
||||||
def handle_update(self, updatesource):
|
def handle_update(self, updatesource):
|
||||||
"""Handle the new update request."""
|
"""Handle the new update request."""
|
||||||
if '{}.{}'.format(self.device_type, self.node_id) not in updatesource:
|
if '{}.{}'.format(self.device_type, self.node_id) not in updatesource:
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of this Switch device if any."""
|
"""Return the name of this Switch device if any."""
|
||||||
return self.node_name
|
return self.node_name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_power_w(self):
|
def current_power_w(self):
|
||||||
"""Return the current power usage in W."""
|
"""Return the current power usage in W."""
|
||||||
return self.session.switch.get_power_usage(self.node_id)
|
return self.session.switch.get_power_usage(self.node_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if switch is on."""
|
"""Return true if switch is on."""
|
||||||
return self.session.switch.get_state(self.node_id)
|
return self.session.switch.get_state(self.node_id)
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
"""Turn the switch on."""
|
"""Turn the switch on."""
|
||||||
self.session.switch.turn_on(self.node_id)
|
self.session.switch.turn_on(self.node_id)
|
||||||
for entity in self.session.entities:
|
for entity in self.session.entities:
|
||||||
entity.handle_update(self.data_updatesource)
|
entity.handle_update(self.data_updatesource)
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
"""Turn the device off."""
|
"""Turn the device off."""
|
||||||
self.session.switch.turn_off(self.node_id)
|
self.session.switch.turn_off(self.node_id)
|
||||||
for entity in self.session.entities:
|
for entity in self.session.entities:
|
||||||
entity.handle_update(self.data_updatesource)
|
entity.handle_update(self.data_updatesource)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update all Node data frome Hive."""
|
"""Update all Node data frome Hive."""
|
||||||
self.session.core.update_data(self.node_id)
|
self.session.core.update_data(self.node_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user