-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
New Hive Component / Platforms #9804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
9c3d11d
New Hive Component / Platforms
Rendili 74e10f3
New Hive Component / Platforms
Rendili b38e659
New Hive Component / Platforms
Rendili 1e9a9c0
New Hive Component / Platforms
Rendili 36e313e
New Hive Component / Platforms
Rendili b6e2df3
New Hive Component / Platforms
Rendili a16df0e
New Hive Component / Platforms
Rendili 863f569
New Hive Component / Platforms
Rendili 1f81751
New Hive Component / Platforms
Rendili 6e302a7
New Hive Component / Platforms
Rendili dca60ef
New Hive Component / Platforms
Rendili 0457a01
New Hive Component / Platforms
Rendili 5e7d872
New Hive Component / Platforms
Rendili 63549cf
New Hive Component / Platforms
Rendili 1595301
Changes
Rendili 6dc23c3
Changes
Rendili 0cc6339
Changes
Rendili 7b54dbd
changes
Rendili 2f4c801
Updates
Rendili b2ccfc3
Updates
Rendili 0860845
Updates
Rendili 098112a
Updates
Rendili 6aed8d5
Updates
Rendili 03d925c
Updates
Rendili c69912d
Sensor code updates
Rendili d4ed607
Sensor code updates
Rendili fe4cbe3
Move sensors to binary sensors
Rendili a63fccf
Quack
Rendili fff1397
Updates - Removed climate related sensors
Rendili 30f5666
sensor fix
Rendili 21c3dc8
binary_sensor updates
Rendili a80dd4b
New Hive Component / Platforms
Rendili b5d7053
New Hive Component / Platforms
Rendili 510f777
New Hive Component / Platforms
Rendili File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
""" | ||
Support for the Hive devices. | ||
|
||
For more details about this platform, please refer to the documentation at | ||
https://home-assistant.io/components/binary_sensor.hive/ | ||
""" | ||
from homeassistant.components.binary_sensor import BinarySensorDevice | ||
from homeassistant.components.hive import DATA_HIVE | ||
|
||
DEPENDENCIES = ['hive'] | ||
|
||
DEVICETYPE_DEVICE_CLASS = {'motionsensor': 'motion', | ||
'contactsensor': 'opening'} | ||
|
||
|
||
def setup_platform(hass, config, add_devices, discovery_info=None): | ||
"""Set up Hive sensor devices.""" | ||
if discovery_info is None: | ||
return | ||
session = hass.data.get(DATA_HIVE) | ||
|
||
add_devices([HiveBinarySensorEntity(session, discovery_info)]) | ||
|
||
|
||
class HiveBinarySensorEntity(BinarySensorDevice): | ||
"""Representation of a Hive binary sensor.""" | ||
|
||
def __init__(self, hivesession, hivedevice): | ||
"""Initialize the hive sensor.""" | ||
self.node_id = hivedevice["Hive_NodeID"] | ||
self.node_name = hivedevice["Hive_NodeName"] | ||
self.device_type = hivedevice["HA_DeviceType"] | ||
self.node_device_type = hivedevice["Hive_DeviceType"] | ||
self.session = hivesession | ||
self.data_updatesource = '{}.{}'.format(self.device_type, | ||
self.node_id) | ||
|
||
self.session.entities.append(self) | ||
|
||
def handle_update(self, updatesource): | ||
"""Handle the new update request.""" | ||
if '{}.{}'.format(self.device_type, self.node_id) not in updatesource: | ||
self.schedule_update_ha_state() | ||
|
||
@property | ||
def device_class(self): | ||
"""Return the class of this sensor.""" | ||
return DEVICETYPE_DEVICE_CLASS.get(self.node_device_type) | ||
|
||
@property | ||
def name(self): | ||
"""Return the name of the binary sensor.""" | ||
return self.node_name | ||
|
||
@property | ||
def is_on(self): | ||
"""Return true if the binary sensor is on.""" | ||
return self.session.sensor.get_state(self.node_id, | ||
self.node_device_type) | ||
|
||
def update(self): | ||
"""Update all Node data frome Hive.""" | ||
self.session.core.update_data(self.node_id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
""" | ||
Support for the Hive devices. | ||
|
||
For more details about this platform, please refer to the documentation at | ||
https://home-assistant.io/components/climate.hive/ | ||
""" | ||
from homeassistant.components.climate import (ClimateDevice, | ||
STATE_AUTO, STATE_HEAT, | ||
STATE_OFF, STATE_ON) | ||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS | ||
from homeassistant.components.hive import DATA_HIVE | ||
|
||
DEPENDENCIES = ['hive'] | ||
HIVE_TO_HASS_STATE = {'SCHEDULE': STATE_AUTO, 'MANUAL': STATE_HEAT, | ||
'ON': STATE_ON, 'OFF': STATE_OFF} | ||
HASS_TO_HIVE_STATE = {STATE_AUTO: 'SCHEDULE', STATE_HEAT: 'MANUAL', | ||
STATE_ON: 'ON', STATE_OFF: 'OFF'} | ||
|
||
|
||
def setup_platform(hass, config, add_devices, discovery_info=None): | ||
"""Set up Hive climate devices.""" | ||
if discovery_info is None: | ||
return | ||
session = hass.data.get(DATA_HIVE) | ||
|
||
add_devices([HiveClimateEntity(session, discovery_info)]) | ||
|
||
|
||
class HiveClimateEntity(ClimateDevice): | ||
"""Hive Climate Device.""" | ||
|
||
def __init__(self, hivesession, hivedevice): | ||
"""Initialize the Climate device.""" | ||
self.node_id = hivedevice["Hive_NodeID"] | ||
self.node_name = hivedevice["Hive_NodeName"] | ||
self.device_type = hivedevice["HA_DeviceType"] | ||
self.session = hivesession | ||
self.data_updatesource = '{}.{}'.format(self.device_type, | ||
self.node_id) | ||
|
||
if self.device_type == "Heating": | ||
self.modes = [STATE_AUTO, STATE_HEAT, STATE_OFF] | ||
elif self.device_type == "HotWater": | ||
self.modes = [STATE_AUTO, STATE_ON, STATE_OFF] | ||
|
||
self.session.entities.append(self) | ||
|
||
def handle_update(self, updatesource): | ||
"""Handle the new update request.""" | ||
if '{}.{}'.format(self.device_type, self.node_id) not in updatesource: | ||
self.schedule_update_ha_state() | ||
|
||
@property | ||
def name(self): | ||
"""Return the name of the Climate device.""" | ||
friendly_name = "Climate Device" | ||
if self.device_type == "Heating": | ||
friendly_name = "Heating" | ||
if self.node_name is not None: | ||
friendly_name = '{} {}'.format(self.node_name, friendly_name) | ||
elif self.device_type == "HotWater": | ||
friendly_name = "Hot Water" | ||
return friendly_name | ||
|
||
@property | ||
def temperature_unit(self): | ||
"""Return the unit of measurement.""" | ||
return TEMP_CELSIUS | ||
|
||
@property | ||
def current_temperature(self): | ||
"""Return the current temperature.""" | ||
if self.device_type == "Heating": | ||
return self.session.heating.current_temperature(self.node_id) | ||
|
||
@property | ||
def target_temperature(self): | ||
"""Return the target temperature.""" | ||
if self.device_type == "Heating": | ||
return self.session.heating.get_target_temperature(self.node_id) | ||
|
||
@property | ||
def min_temp(self): | ||
"""Return minimum temperature.""" | ||
if self.device_type == "Heating": | ||
return self.session.heating.min_temperature(self.node_id) | ||
|
||
@property | ||
def max_temp(self): | ||
"""Return the maximum temperature.""" | ||
if self.device_type == "Heating": | ||
return self.session.heating.max_temperature(self.node_id) | ||
|
||
@property | ||
def operation_list(self): | ||
"""List of the operation modes.""" | ||
return self.modes | ||
|
||
@property | ||
def current_operation(self): | ||
"""Return current mode.""" | ||
if self.device_type == "Heating": | ||
currentmode = self.session.heating.get_mode(self.node_id) | ||
elif self.device_type == "HotWater": | ||
currentmode = self.session.hotwater.get_mode(self.node_id) | ||
return HIVE_TO_HASS_STATE.get(currentmode) | ||
|
||
def set_operation_mode(self, operation_mode): | ||
"""Set new Heating mode.""" | ||
new_mode = HASS_TO_HIVE_STATE.get(operation_mode) | ||
if self.device_type == "Heating": | ||
self.session.heating.set_mode(self.node_id, new_mode) | ||
elif self.device_type == "HotWater": | ||
self.session.hotwater.set_mode(self.node_id, new_mode) | ||
|
||
for entity in self.session.entities: | ||
entity.handle_update(self.data_updatesource) | ||
|
||
def set_temperature(self, **kwargs): | ||
"""Set new target temperature.""" | ||
new_temperature = kwargs.get(ATTR_TEMPERATURE) | ||
if new_temperature is not None: | ||
if self.device_type == "Heating": | ||
self.session.heating.set_target_temperature(self.node_id, | ||
new_temperature) | ||
|
||
for entity in self.session.entities: | ||
entity.handle_update(self.data_updatesource) | ||
|
||
def update(self): | ||
"""Update all Node data frome Hive.""" | ||
self.session.core.update_data(self.node_id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
""" | ||
Support for the Hive devices. | ||
|
||
For more details about this platform, please refer to the documentation at | ||
https://home-assistant.io/components/hive/ | ||
""" | ||
import logging | ||
import voluptuous as vol | ||
|
||
from homeassistant.const import (CONF_PASSWORD, CONF_SCAN_INTERVAL, | ||
CONF_USERNAME) | ||
import homeassistant.helpers.config_validation as cv | ||
from homeassistant.helpers.discovery import load_platform | ||
|
||
REQUIREMENTS = ['pyhiveapi==0.2.5'] | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
DOMAIN = 'hive' | ||
DATA_HIVE = 'data_hive' | ||
DEVICETYPES = { | ||
'binary_sensor': 'device_list_binary_sensor', | ||
'climate': 'device_list_climate', | ||
'light': 'device_list_light', | ||
'switch': 'device_list_plug', | ||
'sensor': 'device_list_sensor', | ||
} | ||
|
||
CONFIG_SCHEMA = vol.Schema({ | ||
DOMAIN: vol.Schema({ | ||
vol.Required(CONF_PASSWORD): cv.string, | ||
vol.Required(CONF_USERNAME): cv.string, | ||
vol.Optional(CONF_SCAN_INTERVAL, default=2): cv.positive_int, | ||
}) | ||
}, extra=vol.ALLOW_EXTRA) | ||
|
||
|
||
class HiveSession: | ||
"""Initiate Hive Session Class.""" | ||
|
||
entities = [] | ||
core = None | ||
heating = None | ||
hotwater = None | ||
light = None | ||
sensor = None | ||
switch = None | ||
|
||
|
||
def setup(hass, config): | ||
"""Set up the Hive Component.""" | ||
from pyhiveapi import Pyhiveapi | ||
|
||
session = HiveSession() | ||
session.core = Pyhiveapi() | ||
|
||
username = config[DOMAIN][CONF_USERNAME] | ||
password = config[DOMAIN][CONF_PASSWORD] | ||
update_interval = config[DOMAIN][CONF_SCAN_INTERVAL] | ||
|
||
devicelist = session.core.initialise_api(username, | ||
password, | ||
update_interval) | ||
|
||
if devicelist is None: | ||
_LOGGER.error("Hive API initialization failed") | ||
return False | ||
|
||
session.sensor = Pyhiveapi.Sensor() | ||
session.heating = Pyhiveapi.Heating() | ||
session.hotwater = Pyhiveapi.Hotwater() | ||
session.light = Pyhiveapi.Light() | ||
session.switch = Pyhiveapi.Switch() | ||
hass.data[DATA_HIVE] = session | ||
|
||
for ha_type, hive_type in DEVICETYPES.items(): | ||
for key, devices in devicelist.items(): | ||
if key == hive_type: | ||
for hivedevice in devices: | ||
load_platform(hass, ha_type, DOMAIN, hivedevice, config) | ||
return True |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what's happening here. Why should all hive entities except the one where the update originated from be scheduled for a state update?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The entity that is not updated in this
handle_update
is the one that made the request for all entities to be updated. I excluded it as it already had the updated data as it was the one that made the call which resulted in new dataThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But why should a change in state of one entity update the state of the other entities? Why should there be that connection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because, when you set a new temperature for example, the Hive api returns the latest data for all your Hive devices, so to me it makes sense to utilise as soon as possible that latest data by getting all the HA entities to refresh. They wont go out to the Hive api as it has only just been retrieved to HA cache. It is the same for when you set temperature, or turn on a light, each time you do anything with the Hive API it will return the latest data for all devices.
It there any reason why it is not allowed to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I hadn't read all the previous discussions. As said in those, the dispatcher could be used for this case. But I think it's ok like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, great, thanks.