From 3da4e2aa55b550183d47cd7c786c2791e46ae72c Mon Sep 17 00:00:00 2001 From: KJonline Date: Wed, 4 Sep 2019 20:52:29 +0100 Subject: [PATCH 01/26] Start the Boost work --- homeassistant/components/hive/water_heater.py | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/hive/water_heater.py b/homeassistant/components/hive/water_heater.py index f186d804d34c89..c3c3003bb5044c 100644 --- a/homeassistant/components/hive/water_heater.py +++ b/homeassistant/components/hive/water_heater.py @@ -1,6 +1,7 @@ """Support for hive water heaters.""" -from homeassistant.const import TEMP_CELSIUS - +import voluptuous as vol +from homeassistant.const import (TEMP_CELSIUS, ATTR_ENTITY_ID, ATTR_TIME) +import homeassistant.helpers.config_validation as cv from homeassistant.components.water_heater import ( STATE_ECO, STATE_ON, @@ -8,20 +9,22 @@ SUPPORT_OPERATION_MODE, WaterHeaterDevice, ) - from . import DATA_HIVE, DOMAIN - +from datetime import time SUPPORT_FLAGS_HEATER = SUPPORT_OPERATION_MODE HIVE_TO_HASS_STATE = {"SCHEDULE": STATE_ECO, "ON": STATE_ON, "OFF": STATE_OFF} - HASS_TO_HIVE_STATE = {STATE_ECO: "SCHEDULE", STATE_ON: "ON", STATE_OFF: "OFF"} - SUPPORT_WATER_HEATER = [STATE_ECO, STATE_ON, STATE_OFF] +BOOST_ON_SCHEMA = { + vol.Required(ATTR_ENTITY_ID): cv.entity_ids, + vol.Required(ATTR_TIME): cv.string +} + def setup_platform(hass, config, add_entities, discovery_info=None): - """Set up the Wink water heater devices.""" + """Set up the Hive water heater devices.""" if discovery_info is None: return if discovery_info["HA_DeviceType"] != "HotWater": @@ -32,6 +35,17 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities([water_heater]) + def boost_on(call): + """Handle the service call.""" + session = hass.data.get(DATA_HIVE) + entity_id = call.data.get(ATTR_ENTITY_ID) + boost_time = time(call.data.get(ATTR_TIME)) + total_time = boost_time.hour * 60 + boost_time.minute + + session.hotwater.turn_boost_on(entity_id, total_time) + + hass.services.register(DOMAIN, 'boost_on', boost_on, schema=BOOST_ON_SCHEMA) + class HiveWaterHeater(WaterHeaterDevice): """Hive Water Heater Device.""" From 40546d0c92eb2a0ea3dce9067e3e3de5a6ffd79c Mon Sep 17 00:00:00 2001 From: KJonline Date: Wed, 4 Sep 2019 20:57:11 +0100 Subject: [PATCH 02/26] Add services.yaml --- homeassistant/components/hive/services.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 homeassistant/components/hive/services.yaml diff --git a/homeassistant/components/hive/services.yaml b/homeassistant/components/hive/services.yaml new file mode 100644 index 00000000000000..2a6f37ed782643 --- /dev/null +++ b/homeassistant/components/hive/services.yaml @@ -0,0 +1,10 @@ +boost_on: + description: 'Set the home/away mode for a Nest structure. Set to away mode will + also set Estimated Arrival Time if provided. Set ETA will cause the thermostat + to begin warming or cooling the home before the user arrives. After ETA set other + Automation can read ETA sensor as a signal to prepare the home for the user''s + arrival.' + fields: + entity_id: {description: Optional Estimated Arrival Time from now., example: '0:10'} + time: {description: Optional ETA window. Default is 1 minute., example: '0:5'} + home_mode: {description: home or away, example: home} From 55f1c07e319b3b5a5191e96e411cbffd738e662d Mon Sep 17 00:00:00 2001 From: Khole Date: Sun, 8 Sep 2019 11:41:58 +0100 Subject: [PATCH 03/26] Added Services #2 --- homeassistant/components/hive/__init__.py | 1 + homeassistant/components/hive/climate.py | 33 +++++++++++++++++-- homeassistant/components/hive/services.yaml | 33 +++++++++++++++---- homeassistant/components/hive/water_heater.py | 9 +++-- 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/hive/__init__.py b/homeassistant/components/hive/__init__.py index fc96f2d8c966f7..a416fbb63223b4 100644 --- a/homeassistant/components/hive/__init__.py +++ b/homeassistant/components/hive/__init__.py @@ -39,6 +39,7 @@ class HiveSession: """Initiate Hive Session Class.""" entities = [] + entity_lookup = {} core = None heating = None hotwater = None diff --git a/homeassistant/components/hive/climate.py b/homeassistant/components/hive/climate.py index d4a1c915518eff..9603ed38704d38 100644 --- a/homeassistant/components/hive/climate.py +++ b/homeassistant/components/hive/climate.py @@ -1,5 +1,13 @@ """Support for the Hive climate devices.""" + +from homeassistant.const import ( + ATTR_TEMPERATURE, + TEMP_CELSIUS, + ATTR_ENTITY_ID, + ATTR_TIME, +) from homeassistant.components.climate import ClimateDevice +import homeassistant.helpers.config_validation as cv from homeassistant.components.climate.const import ( HVAC_MODE_AUTO, HVAC_MODE_HEAT, @@ -9,9 +17,8 @@ SUPPORT_TARGET_TEMPERATURE, PRESET_NONE, ) -from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS - from . import DATA_HIVE, DOMAIN +import voluptuous as vol HIVE_TO_HASS_STATE = { "SCHEDULE": HVAC_MODE_AUTO, @@ -25,6 +32,12 @@ HVAC_MODE_OFF: "OFF", } +BOOST_HEATING_SCHEMA = { + vol.Required(ATTR_ENTITY_ID): cv.entity_id, + vol.Required(ATTR_TIME): cv.time, + vol.Required(ATTR_TEMPERATURE): cv.positive_int, +} + SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE SUPPORT_HVAC = [HVAC_MODE_AUTO, HVAC_MODE_HEAT, HVAC_MODE_OFF] SUPPORT_PRESET = [PRESET_NONE, PRESET_BOOST] @@ -42,6 +55,21 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities([climate]) + def heating_boost(service): + """Handle the service call.""" + session = hass.data.get(DATA_HIVE) + entity_id = service.data.get(ATTR_ENTITY_ID) + node_id = session.entity_lookup[entity_id] + boost_time = time(service.data.get(ATTR_TIME)) + total_time = boost_time.hour * 60 + boost_time.minute + temperature = service.data.get(ATTR_TEMPERATURE) + + session.heating.turn_boost_on(self.node_id, 30, temperature) + + hass.services.register( + DOMAIN, "boost_heating", heating_boost, schema=BOOST_HEATING_SCHEMA + ) + class HiveClimateEntity(ClimateDevice): """Hive Climate Device.""" @@ -147,6 +175,7 @@ async def async_added_to_hass(self): """When entity is added to Home Assistant.""" await super().async_added_to_hass() self.session.entities.append(self) + self.session.entity_lookup.update({self.entity_id: self.node_id}) def set_hvac_mode(self, hvac_mode): """Set new target hvac mode.""" diff --git a/homeassistant/components/hive/services.yaml b/homeassistant/components/hive/services.yaml index 2a6f37ed782643..806947cfd4fdfd 100644 --- a/homeassistant/components/hive/services.yaml +++ b/homeassistant/components/hive/services.yaml @@ -1,10 +1,29 @@ -boost_on: - description: 'Set the home/away mode for a Nest structure. Set to away mode will +boost_heating: + description: "Set the boost mode ON defining the period of time and the desired target temperature." + fields: + entity_id: + { + description: The Entity which the required boost is to be set., + example: "water_heater.hotwater", + } + time: + { description: Set the time period for the boost., example: "01:30:00" } + temperature: + { description: Set the time period for the boost., example: "01:30:00" } +boost_hotwater: + description: + "Set the home/away mode for a Nest structure. Set to away mode will also set Estimated Arrival Time if provided. Set ETA will cause the thermostat to begin warming or cooling the home before the user arrives. After ETA set other - Automation can read ETA sensor as a signal to prepare the home for the user''s - arrival.' + Automation can read ETA sensor as a signal to prepare the home for the user's + arrival." fields: - entity_id: {description: Optional Estimated Arrival Time from now., example: '0:10'} - time: {description: Optional ETA window. Default is 1 minute., example: '0:5'} - home_mode: {description: home or away, example: home} + entity_id: + { + description: The Entity which the required boost is to be set., + example: "water_heater.hotwater", + } + time: + { description: Set the time period for the boost., example: "01:30:00" } + on_off: + { description: Set the time period for the boost., example: "01:30:00" } diff --git a/homeassistant/components/hive/water_heater.py b/homeassistant/components/hive/water_heater.py index c3c3003bb5044c..5bea664527ae1d 100644 --- a/homeassistant/components/hive/water_heater.py +++ b/homeassistant/components/hive/water_heater.py @@ -1,6 +1,6 @@ """Support for hive water heaters.""" import voluptuous as vol -from homeassistant.const import (TEMP_CELSIUS, ATTR_ENTITY_ID, ATTR_TIME) +from homeassistant.const import TEMP_CELSIUS, ATTR_ENTITY_ID, ATTR_TIME import homeassistant.helpers.config_validation as cv from homeassistant.components.water_heater import ( STATE_ECO, @@ -11,6 +11,7 @@ ) from . import DATA_HIVE, DOMAIN from datetime import time + SUPPORT_FLAGS_HEATER = SUPPORT_OPERATION_MODE HIVE_TO_HASS_STATE = {"SCHEDULE": STATE_ECO, "ON": STATE_ON, "OFF": STATE_OFF} @@ -19,7 +20,7 @@ BOOST_ON_SCHEMA = { vol.Required(ATTR_ENTITY_ID): cv.entity_ids, - vol.Required(ATTR_TIME): cv.string + vol.Required(ATTR_TIME): cv.string, } @@ -39,12 +40,13 @@ def boost_on(call): """Handle the service call.""" session = hass.data.get(DATA_HIVE) entity_id = call.data.get(ATTR_ENTITY_ID) + node_id = session.entity_lookup[entity_id] boost_time = time(call.data.get(ATTR_TIME)) total_time = boost_time.hour * 60 + boost_time.minute session.hotwater.turn_boost_on(entity_id, total_time) - hass.services.register(DOMAIN, 'boost_on', boost_on, schema=BOOST_ON_SCHEMA) + hass.services.register(DOMAIN, "boost_on", boost_on, schema=BOOST_ON_SCHEMA) class HiveWaterHeater(WaterHeaterDevice): @@ -106,6 +108,7 @@ async def async_added_to_hass(self): """When entity is added to Home Assistant.""" await super().async_added_to_hass() self.session.entities.append(self) + self.session.entity_lookup.update({self.entity_id: self.node_id}) def set_operation_mode(self, operation_mode): """Set operation mode.""" From 9ecbc4993f43dd9baec8372a9a55bbc74229b62c Mon Sep 17 00:00:00 2001 From: KJonline Date: Wed, 4 Sep 2019 20:52:29 +0100 Subject: [PATCH 04/26] Start the Boost work --- homeassistant/components/hive/water_heater.py | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/hive/water_heater.py b/homeassistant/components/hive/water_heater.py index 1b009582c1aec7..8d7beec91ba1a2 100644 --- a/homeassistant/components/hive/water_heater.py +++ b/homeassistant/components/hive/water_heater.py @@ -1,6 +1,7 @@ """Support for hive water heaters.""" -from homeassistant.const import TEMP_CELSIUS - +import voluptuous as vol +from homeassistant.const import (TEMP_CELSIUS, ATTR_ENTITY_ID, ATTR_TIME) +import homeassistant.helpers.config_validation as cv from homeassistant.components.water_heater import ( STATE_ECO, STATE_ON, @@ -8,20 +9,22 @@ SUPPORT_OPERATION_MODE, WaterHeaterDevice, ) - from . import DATA_HIVE, DOMAIN - +from datetime import time SUPPORT_FLAGS_HEATER = SUPPORT_OPERATION_MODE HIVE_TO_HASS_STATE = {"SCHEDULE": STATE_ECO, "ON": STATE_ON, "OFF": STATE_OFF} - HASS_TO_HIVE_STATE = {STATE_ECO: "SCHEDULE", STATE_ON: "ON", STATE_OFF: "OFF"} - SUPPORT_WATER_HEATER = [STATE_ECO, STATE_ON, STATE_OFF] +BOOST_ON_SCHEMA = { + vol.Required(ATTR_ENTITY_ID): cv.entity_ids, + vol.Required(ATTR_TIME): cv.string +} + def setup_platform(hass, config, add_entities, discovery_info=None): - """Set up the Wink water heater devices.""" + """Set up the Hive water heater devices.""" if discovery_info is None: return if discovery_info["HA_DeviceType"] != "HotWater": @@ -32,6 +35,17 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities([water_heater]) + def boost_on(call): + """Handle the service call.""" + session = hass.data.get(DATA_HIVE) + entity_id = call.data.get(ATTR_ENTITY_ID) + boost_time = time(call.data.get(ATTR_TIME)) + total_time = boost_time.hour * 60 + boost_time.minute + + session.hotwater.turn_boost_on(entity_id, total_time) + + hass.services.register(DOMAIN, 'boost_on', boost_on, schema=BOOST_ON_SCHEMA) + class HiveWaterHeater(WaterHeaterDevice): """Hive Water Heater Device.""" From a6ec9dfc73b9d040e1bf5d41edeb9b367b666c33 Mon Sep 17 00:00:00 2001 From: KJonline Date: Wed, 4 Sep 2019 20:57:11 +0100 Subject: [PATCH 05/26] Add services.yaml --- homeassistant/components/hive/services.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 homeassistant/components/hive/services.yaml diff --git a/homeassistant/components/hive/services.yaml b/homeassistant/components/hive/services.yaml new file mode 100644 index 00000000000000..2a6f37ed782643 --- /dev/null +++ b/homeassistant/components/hive/services.yaml @@ -0,0 +1,10 @@ +boost_on: + description: 'Set the home/away mode for a Nest structure. Set to away mode will + also set Estimated Arrival Time if provided. Set ETA will cause the thermostat + to begin warming or cooling the home before the user arrives. After ETA set other + Automation can read ETA sensor as a signal to prepare the home for the user''s + arrival.' + fields: + entity_id: {description: Optional Estimated Arrival Time from now., example: '0:10'} + time: {description: Optional ETA window. Default is 1 minute., example: '0:5'} + home_mode: {description: home or away, example: home} From 8d1d373d8d30e8539d82be0a9d8517fbc603efdf Mon Sep 17 00:00:00 2001 From: Khole Date: Sun, 8 Sep 2019 11:41:58 +0100 Subject: [PATCH 06/26] Added Services #2 --- homeassistant/components/hive/__init__.py | 1 + homeassistant/components/hive/climate.py | 33 +++++++++++++++++-- homeassistant/components/hive/services.yaml | 33 +++++++++++++++---- homeassistant/components/hive/water_heater.py | 9 +++-- 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/hive/__init__.py b/homeassistant/components/hive/__init__.py index fc96f2d8c966f7..a416fbb63223b4 100644 --- a/homeassistant/components/hive/__init__.py +++ b/homeassistant/components/hive/__init__.py @@ -39,6 +39,7 @@ class HiveSession: """Initiate Hive Session Class.""" entities = [] + entity_lookup = {} core = None heating = None hotwater = None diff --git a/homeassistant/components/hive/climate.py b/homeassistant/components/hive/climate.py index 861957e6ef0166..cd6a83b901e481 100644 --- a/homeassistant/components/hive/climate.py +++ b/homeassistant/components/hive/climate.py @@ -1,5 +1,13 @@ """Support for the Hive climate devices.""" + +from homeassistant.const import ( + ATTR_TEMPERATURE, + TEMP_CELSIUS, + ATTR_ENTITY_ID, + ATTR_TIME, +) from homeassistant.components.climate import ClimateDevice +import homeassistant.helpers.config_validation as cv from homeassistant.components.climate.const import ( HVAC_MODE_AUTO, HVAC_MODE_HEAT, @@ -9,9 +17,8 @@ SUPPORT_TARGET_TEMPERATURE, PRESET_NONE, ) -from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS - from . import DATA_HIVE, DOMAIN +import voluptuous as vol HIVE_TO_HASS_STATE = { "SCHEDULE": HVAC_MODE_AUTO, @@ -25,6 +32,12 @@ HVAC_MODE_OFF: "OFF", } +BOOST_HEATING_SCHEMA = { + vol.Required(ATTR_ENTITY_ID): cv.entity_id, + vol.Required(ATTR_TIME): cv.time, + vol.Required(ATTR_TEMPERATURE): cv.positive_int, +} + SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE SUPPORT_HVAC = [HVAC_MODE_AUTO, HVAC_MODE_HEAT, HVAC_MODE_OFF] SUPPORT_PRESET = [PRESET_NONE, PRESET_BOOST] @@ -42,6 +55,21 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities([climate]) + def heating_boost(service): + """Handle the service call.""" + session = hass.data.get(DATA_HIVE) + entity_id = service.data.get(ATTR_ENTITY_ID) + node_id = session.entity_lookup[entity_id] + boost_time = time(service.data.get(ATTR_TIME)) + total_time = boost_time.hour * 60 + boost_time.minute + temperature = service.data.get(ATTR_TEMPERATURE) + + session.heating.turn_boost_on(self.node_id, 30, temperature) + + hass.services.register( + DOMAIN, "boost_heating", heating_boost, schema=BOOST_HEATING_SCHEMA + ) + class HiveClimateEntity(ClimateDevice): """Hive Climate Device.""" @@ -147,6 +175,7 @@ async def async_added_to_hass(self): """When entity is added to Home Assistant.""" await super().async_added_to_hass() self.session.entities.append(self) + self.session.entity_lookup.update({self.entity_id: self.node_id}) def set_hvac_mode(self, hvac_mode): """Set new target hvac mode.""" diff --git a/homeassistant/components/hive/services.yaml b/homeassistant/components/hive/services.yaml index 2a6f37ed782643..806947cfd4fdfd 100644 --- a/homeassistant/components/hive/services.yaml +++ b/homeassistant/components/hive/services.yaml @@ -1,10 +1,29 @@ -boost_on: - description: 'Set the home/away mode for a Nest structure. Set to away mode will +boost_heating: + description: "Set the boost mode ON defining the period of time and the desired target temperature." + fields: + entity_id: + { + description: The Entity which the required boost is to be set., + example: "water_heater.hotwater", + } + time: + { description: Set the time period for the boost., example: "01:30:00" } + temperature: + { description: Set the time period for the boost., example: "01:30:00" } +boost_hotwater: + description: + "Set the home/away mode for a Nest structure. Set to away mode will also set Estimated Arrival Time if provided. Set ETA will cause the thermostat to begin warming or cooling the home before the user arrives. After ETA set other - Automation can read ETA sensor as a signal to prepare the home for the user''s - arrival.' + Automation can read ETA sensor as a signal to prepare the home for the user's + arrival." fields: - entity_id: {description: Optional Estimated Arrival Time from now., example: '0:10'} - time: {description: Optional ETA window. Default is 1 minute., example: '0:5'} - home_mode: {description: home or away, example: home} + entity_id: + { + description: The Entity which the required boost is to be set., + example: "water_heater.hotwater", + } + time: + { description: Set the time period for the boost., example: "01:30:00" } + on_off: + { description: Set the time period for the boost., example: "01:30:00" } diff --git a/homeassistant/components/hive/water_heater.py b/homeassistant/components/hive/water_heater.py index 8d7beec91ba1a2..ca1369b94cdf25 100644 --- a/homeassistant/components/hive/water_heater.py +++ b/homeassistant/components/hive/water_heater.py @@ -1,6 +1,6 @@ """Support for hive water heaters.""" import voluptuous as vol -from homeassistant.const import (TEMP_CELSIUS, ATTR_ENTITY_ID, ATTR_TIME) +from homeassistant.const import TEMP_CELSIUS, ATTR_ENTITY_ID, ATTR_TIME import homeassistant.helpers.config_validation as cv from homeassistant.components.water_heater import ( STATE_ECO, @@ -11,6 +11,7 @@ ) from . import DATA_HIVE, DOMAIN from datetime import time + SUPPORT_FLAGS_HEATER = SUPPORT_OPERATION_MODE HIVE_TO_HASS_STATE = {"SCHEDULE": STATE_ECO, "ON": STATE_ON, "OFF": STATE_OFF} @@ -19,7 +20,7 @@ BOOST_ON_SCHEMA = { vol.Required(ATTR_ENTITY_ID): cv.entity_ids, - vol.Required(ATTR_TIME): cv.string + vol.Required(ATTR_TIME): cv.string, } @@ -39,12 +40,13 @@ def boost_on(call): """Handle the service call.""" session = hass.data.get(DATA_HIVE) entity_id = call.data.get(ATTR_ENTITY_ID) + node_id = session.entity_lookup[entity_id] boost_time = time(call.data.get(ATTR_TIME)) total_time = boost_time.hour * 60 + boost_time.minute session.hotwater.turn_boost_on(entity_id, total_time) - hass.services.register(DOMAIN, 'boost_on', boost_on, schema=BOOST_ON_SCHEMA) + hass.services.register(DOMAIN, "boost_on", boost_on, schema=BOOST_ON_SCHEMA) class HiveWaterHeater(WaterHeaterDevice): @@ -106,6 +108,7 @@ async def async_added_to_hass(self): """When entity is added to Home Assistant.""" await super().async_added_to_hass() self.session.entities.append(self) + self.session.entity_lookup.update({self.entity_id: self.node_id}) def set_operation_mode(self, operation_mode): """Set operation mode.""" From a1eb496a35f06105aac9b8a8de132283a93c58bd Mon Sep 17 00:00:00 2001 From: Khole Date: Sun, 8 Sep 2019 15:34:24 +0100 Subject: [PATCH 07/26] Working Services --- homeassistant/components/hive/climate.py | 34 +++++++--------- homeassistant/components/hive/services.yaml | 30 +++++++------- homeassistant/components/hive/water_heater.py | 39 +++++++++++-------- 3 files changed, 52 insertions(+), 51 deletions(-) diff --git a/homeassistant/components/hive/climate.py b/homeassistant/components/hive/climate.py index cd6a83b901e481..c5055b90bbb815 100644 --- a/homeassistant/components/hive/climate.py +++ b/homeassistant/components/hive/climate.py @@ -1,11 +1,6 @@ """Support for the Hive climate devices.""" -from homeassistant.const import ( - ATTR_TEMPERATURE, - TEMP_CELSIUS, - ATTR_ENTITY_ID, - ATTR_TIME, -) +from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, ATTR_ENTITY_ID from homeassistant.components.climate import ClimateDevice import homeassistant.helpers.config_validation as cv from homeassistant.components.climate.const import ( @@ -32,15 +27,18 @@ HVAC_MODE_OFF: "OFF", } -BOOST_HEATING_SCHEMA = { - vol.Required(ATTR_ENTITY_ID): cv.entity_id, - vol.Required(ATTR_TIME): cv.time, - vol.Required(ATTR_TEMPERATURE): cv.positive_int, -} - SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE SUPPORT_HVAC = [HVAC_MODE_AUTO, HVAC_MODE_HEAT, HVAC_MODE_OFF] SUPPORT_PRESET = [PRESET_NONE, PRESET_BOOST] +SERVICE_BOOST_HEATING = "boost_heating" +ATTR_BOOST_MINUTES = "minutes" +BOOST_HEATING_SCHEMA = vol.Schema( + { + vol.Required(ATTR_ENTITY_ID): cv.entity_id, + vol.Required(ATTR_BOOST_MINUTES): cv.positive_int, + vol.Required(ATTR_TEMPERATURE): cv.string, + } +) def setup_platform(hass, config, add_entities, discovery_info=None): @@ -58,16 +56,14 @@ def setup_platform(hass, config, add_entities, discovery_info=None): def heating_boost(service): """Handle the service call.""" session = hass.data.get(DATA_HIVE) - entity_id = service.data.get(ATTR_ENTITY_ID) - node_id = session.entity_lookup[entity_id] - boost_time = time(service.data.get(ATTR_TIME)) - total_time = boost_time.hour * 60 + boost_time.minute - temperature = service.data.get(ATTR_TEMPERATURE) + entity = session.entity_lookup[service.data.get(ATTR_ENTITY_ID)] + time = service.data.get(ATTR_BOOST_MINUTES) + temperature = float(service.data.get(ATTR_TEMPERATURE)) - session.heating.turn_boost_on(self.node_id, 30, temperature) + session.heating.turn_boost_on(entity, time, temperature) hass.services.register( - DOMAIN, "boost_heating", heating_boost, schema=BOOST_HEATING_SCHEMA + DOMAIN, SERVICE_BOOST_HEATING, heating_boost, schema=BOOST_HEATING_SCHEMA ) diff --git a/homeassistant/components/hive/services.yaml b/homeassistant/components/hive/services.yaml index 806947cfd4fdfd..74d877f9110beb 100644 --- a/homeassistant/components/hive/services.yaml +++ b/homeassistant/components/hive/services.yaml @@ -1,29 +1,27 @@ boost_heating: - description: "Set the boost mode ON defining the period of time and the desired target temperature." + description: "Set the boost mode ON defining the period of time and the desired target temperature + for the boost." fields: entity_id: { - description: The Entity which the required boost is to be set., - example: "water_heater.hotwater", + description: Enter the entity_id for the device reuired to set the boost mode., + example: "climate.heating", } - time: - { description: Set the time period for the boost., example: "01:30:00" } + minutes: + { description: Set the duration of boost in minutes., example: "90" } temperature: - { description: Set the time period for the boost., example: "01:30:00" } + { + description: Set the target temperature for the boost period., + example: "20.5", + } boost_hotwater: description: - "Set the home/away mode for a Nest structure. Set to away mode will - also set Estimated Arrival Time if provided. Set ETA will cause the thermostat - to begin warming or cooling the home before the user arrives. After ETA set other - Automation can read ETA sensor as a signal to prepare the home for the user's - arrival." + "Set the boost mode ON or OFF defining the period of time for the boost." fields: entity_id: { - description: The Entity which the required boost is to be set., + description: Enter the entity_id for the device reuired to set the boost mode., example: "water_heater.hotwater", } - time: - { description: Set the time period for the boost., example: "01:30:00" } - on_off: - { description: Set the time period for the boost., example: "01:30:00" } + minutes: { description: Set the duration of boost in minutes., example: "90" } + on_off: { description: Set the boost function on or off., example: "on or off" } diff --git a/homeassistant/components/hive/water_heater.py b/homeassistant/components/hive/water_heater.py index ca1369b94cdf25..d776f8d078aafe 100644 --- a/homeassistant/components/hive/water_heater.py +++ b/homeassistant/components/hive/water_heater.py @@ -1,6 +1,6 @@ """Support for hive water heaters.""" import voluptuous as vol -from homeassistant.const import TEMP_CELSIUS, ATTR_ENTITY_ID, ATTR_TIME +from homeassistant.const import TEMP_CELSIUS, ATTR_ENTITY_ID, ATTR_COMMAND import homeassistant.helpers.config_validation as cv from homeassistant.components.water_heater import ( STATE_ECO, @@ -10,18 +10,21 @@ WaterHeaterDevice, ) from . import DATA_HIVE, DOMAIN -from datetime import time SUPPORT_FLAGS_HEATER = SUPPORT_OPERATION_MODE HIVE_TO_HASS_STATE = {"SCHEDULE": STATE_ECO, "ON": STATE_ON, "OFF": STATE_OFF} HASS_TO_HIVE_STATE = {STATE_ECO: "SCHEDULE", STATE_ON: "ON", STATE_OFF: "OFF"} SUPPORT_WATER_HEATER = [STATE_ECO, STATE_ON, STATE_OFF] - -BOOST_ON_SCHEMA = { - vol.Required(ATTR_ENTITY_ID): cv.entity_ids, - vol.Required(ATTR_TIME): cv.string, -} +SERVICE_BOOST_HEATING = "boost_hotwater" +ATTR_BOOST_MINUTES = "minutes" +BOOST_HOTWATER_SCHEMA = vol.Schema( + { + vol.Required(ATTR_ENTITY_ID): cv.entity_id, + vol.Required(ATTR_BOOST_MINUTES): cv.positive_int, + vol.Required(ATTR_COMMAND): cv.string, + } +) def setup_platform(hass, config, add_entities, discovery_info=None): @@ -36,17 +39,21 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities([water_heater]) - def boost_on(call): + def hotwater_boost(service): """Handle the service call.""" session = hass.data.get(DATA_HIVE) - entity_id = call.data.get(ATTR_ENTITY_ID) - node_id = session.entity_lookup[entity_id] - boost_time = time(call.data.get(ATTR_TIME)) - total_time = boost_time.hour * 60 + boost_time.minute - - session.hotwater.turn_boost_on(entity_id, total_time) - - hass.services.register(DOMAIN, "boost_on", boost_on, schema=BOOST_ON_SCHEMA) + entity = session.entity_lookup[service.data.get(ATTR_ENTITY_ID)] + time = service.data.get(ATTR_BOOST_MINUTES) + mode = service.data.get(ATTR_COMMAND) + + if mode == "on": + session.hotwater.turn_boost_on(entity, time) + elif mode == "off": + session.hotwater.turn_boost_off(entity) + + hass.services.register( + DOMAIN, SERVICE_BOOST_HEATING, hotwater_boost, schema=BOOST_HOTWATER_SCHEMA + ) class HiveWaterHeater(WaterHeaterDevice): From 2f37b6c1eb0aadd700f7bc84273920f02be4bb73 Mon Sep 17 00:00:00 2001 From: rendili Date: Thu, 12 Sep 2019 14:32:42 +0100 Subject: [PATCH 08/26] pyhiveapi to 0.2.19 --- homeassistant/components/hive/manifest.json | 2 +- requirements_all.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/hive/manifest.json b/homeassistant/components/hive/manifest.json index 886d6841ebb850..2e7c4f4f179dee 100644 --- a/homeassistant/components/hive/manifest.json +++ b/homeassistant/components/hive/manifest.json @@ -3,7 +3,7 @@ "name": "Hive", "documentation": "https://www.home-assistant.io/components/hive", "requirements": [ - "pyhiveapi==0.2.18.1" + "pyhiveapi==0.2.19" ], "dependencies": [], "codeowners": [ diff --git a/requirements_all.txt b/requirements_all.txt index 173e203a892d85..eabb5145946dcb 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1222,7 +1222,7 @@ pyheos==0.6.0 pyhik==0.2.3 # homeassistant.components.hive -pyhiveapi==0.2.18.1 +pyhiveapi==0.2.19 # homeassistant.components.homematic pyhomematic==0.1.60 From 43199ffcb821e3f966dff6d0da9515b853c55dac Mon Sep 17 00:00:00 2001 From: Khole Date: Sat, 14 Sep 2019 11:02:37 +0100 Subject: [PATCH 09/26] Update Libary to 0.2.19 --- homeassistant/components/hive/manifest.json | 2 +- requirements_all.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/hive/manifest.json b/homeassistant/components/hive/manifest.json index 886d6841ebb850..2e7c4f4f179dee 100644 --- a/homeassistant/components/hive/manifest.json +++ b/homeassistant/components/hive/manifest.json @@ -3,7 +3,7 @@ "name": "Hive", "documentation": "https://www.home-assistant.io/components/hive", "requirements": [ - "pyhiveapi==0.2.18.1" + "pyhiveapi==0.2.19" ], "dependencies": [], "codeowners": [ diff --git a/requirements_all.txt b/requirements_all.txt index 173e203a892d85..eabb5145946dcb 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1222,7 +1222,7 @@ pyheos==0.6.0 pyhik==0.2.3 # homeassistant.components.hive -pyhiveapi==0.2.18.1 +pyhiveapi==0.2.19 # homeassistant.components.homematic pyhomematic==0.1.60 From 6488112a5b2a050dccd11c80820c370574275050 Mon Sep 17 00:00:00 2001 From: rendili Date: Tue, 17 Sep 2019 11:38:58 +0100 Subject: [PATCH 10/26] Update Water_heater boost --- homeassistant/components/hive/services.yaml | 2 +- homeassistant/components/hive/water_heater.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/hive/services.yaml b/homeassistant/components/hive/services.yaml index 74d877f9110beb..73841adf6c7b84 100644 --- a/homeassistant/components/hive/services.yaml +++ b/homeassistant/components/hive/services.yaml @@ -21,7 +21,7 @@ boost_hotwater: entity_id: { description: Enter the entity_id for the device reuired to set the boost mode., - example: "water_heater.hotwater", + example: "water_heater.hot_water", } minutes: { description: Set the duration of boost in minutes., example: "90" } on_off: { description: Set the boost function on or off., example: "on or off" } diff --git a/homeassistant/components/hive/water_heater.py b/homeassistant/components/hive/water_heater.py index d776f8d078aafe..64b2605a2b5c92 100644 --- a/homeassistant/components/hive/water_heater.py +++ b/homeassistant/components/hive/water_heater.py @@ -18,6 +18,7 @@ SUPPORT_WATER_HEATER = [STATE_ECO, STATE_ON, STATE_OFF] SERVICE_BOOST_HEATING = "boost_hotwater" ATTR_BOOST_MINUTES = "minutes" +ATTR_COMMAND = "on_off" BOOST_HOTWATER_SCHEMA = vol.Schema( { vol.Required(ATTR_ENTITY_ID): cv.entity_id, From 17f0e2698e8bd0bbad854c81d24390adfbbf974b Mon Sep 17 00:00:00 2001 From: KJonline Date: Fri, 20 Sep 2019 17:48:26 +0100 Subject: [PATCH 11/26] Added Async hass add function --- .../components/hive/binary_sensor.py | 17 ++++++---- homeassistant/components/hive/climate.py | 32 ++++++++++--------- homeassistant/components/hive/light.py | 17 ++++++---- homeassistant/components/hive/sensor.py | 17 ++++++---- homeassistant/components/hive/switch.py | 17 ++++++---- homeassistant/components/hive/water_heater.py | 22 ++++++------- 6 files changed, 72 insertions(+), 50 deletions(-) diff --git a/homeassistant/components/hive/binary_sensor.py b/homeassistant/components/hive/binary_sensor.py index 50c8277302fbc7..32a923ba680db4 100644 --- a/homeassistant/components/hive/binary_sensor.py +++ b/homeassistant/components/hive/binary_sensor.py @@ -28,7 +28,6 @@ def __init__(self, hivesession, hivedevice): self.attributes = {} self.data_updatesource = f"{self.device_type}.{self.node_id}" self._unique_id = f"{self.node_id}-{self.device_type}" - self.session.entities.append(self) @property def unique_id(self): @@ -40,11 +39,6 @@ def device_info(self): """Return device information.""" return {"identifiers": {(DOMAIN, self.unique_id)}, "name": self.name} - def handle_update(self, updatesource): - """Handle the new update request.""" - if f"{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.""" @@ -65,6 +59,17 @@ 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) + async def async_added_to_hass(self): + """When entity is added to Home Assistant.""" + await super().async_added_to_hass() + self.session.entities.append(self) + self.session.entity_lookup.update({self.entity_id: self.node_id}) + + def handle_update(self, updatesource): + """Handle the new update request.""" + if f"{self.device_type}.{self.node_id}" not in updatesource: + self.schedule_update_ha_state() + def update(self): """Update all Node data from Hive.""" self.session.core.update_data(self.node_id) diff --git a/homeassistant/components/hive/climate.py b/homeassistant/components/hive/climate.py index c5055b90bbb815..badd03342892a5 100644 --- a/homeassistant/components/hive/climate.py +++ b/homeassistant/components/hive/climate.py @@ -1,19 +1,21 @@ """Support for the Hive climate devices.""" -from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, ATTR_ENTITY_ID +import voluptuous as vol + from homeassistant.components.climate import ClimateDevice -import homeassistant.helpers.config_validation as cv from homeassistant.components.climate.const import ( HVAC_MODE_AUTO, HVAC_MODE_HEAT, HVAC_MODE_OFF, PRESET_BOOST, + PRESET_NONE, SUPPORT_PRESET_MODE, SUPPORT_TARGET_TEMPERATURE, - PRESET_NONE, ) +from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE, TEMP_CELSIUS +import homeassistant.helpers.config_validation as cv + from . import DATA_HIVE, DOMAIN -import voluptuous as vol HIVE_TO_HASS_STATE = { "SCHEDULE": HVAC_MODE_AUTO, @@ -96,11 +98,6 @@ def supported_features(self): """Return the list of supported features.""" return SUPPORT_FLAGS - def handle_update(self, updatesource): - """Handle the new update request.""" - if f"{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.""" @@ -167,12 +164,6 @@ def preset_modes(self): """Return a list of available preset modes.""" return SUPPORT_PRESET - async def async_added_to_hass(self): - """When entity is added to Home Assistant.""" - await super().async_added_to_hass() - self.session.entities.append(self) - self.session.entity_lookup.update({self.entity_id: self.node_id}) - def set_hvac_mode(self, hvac_mode): """Set new target hvac mode.""" new_mode = HASS_TO_HIVE_STATE[hvac_mode] @@ -205,6 +196,17 @@ def set_preset_mode(self, preset_mode) -> None: for entity in self.session.entities: entity.handle_update(self.data_updatesource) + async def async_added_to_hass(self): + """When entity is added to Home Assistant.""" + await super().async_added_to_hass() + self.session.entities.append(self) + self.session.entity_lookup.update({self.entity_id: self.node_id}) + + def handle_update(self, updatesource): + """Handle the new update request.""" + if f"{self.device_type}.{self.node_id}" not in updatesource: + self.schedule_update_ha_state() + def update(self): """Update all Node data from Hive.""" self.session.core.update_data(self.node_id) diff --git a/homeassistant/components/hive/light.py b/homeassistant/components/hive/light.py index a85c3a43992eb8..00dfaf178e78be 100644 --- a/homeassistant/components/hive/light.py +++ b/homeassistant/components/hive/light.py @@ -35,7 +35,6 @@ def __init__(self, hivesession, hivedevice): self.attributes = {} self.data_updatesource = f"{self.device_type}.{self.node_id}" self._unique_id = f"{self.node_id}-{self.device_type}" - self.session.entities.append(self) @property def unique_id(self): @@ -47,11 +46,6 @@ def device_info(self): """Return device information.""" return {"identifiers": {(DOMAIN, self.unique_id)}, "name": self.name} - def handle_update(self, updatesource): - """Handle the new update request.""" - if f"{self.device_type}.{self.node_id}" not in updatesource: - self.schedule_update_ha_state() - @property def name(self): """Return the display name of this light.""" @@ -156,6 +150,17 @@ def supported_features(self): return supported_features + async def async_added_to_hass(self): + """When entity is added to Home Assistant.""" + await super().async_added_to_hass() + self.session.entities.append(self) + self.session.entity_lookup.update({self.entity_id: self.node_id}) + + def handle_update(self, updatesource): + """Handle the new update request.""" + if f"{self.device_type}.{self.node_id}" not in updatesource: + self.schedule_update_ha_state() + def update(self): """Update all Node data from Hive.""" self.session.core.update_data(self.node_id) diff --git a/homeassistant/components/hive/sensor.py b/homeassistant/components/hive/sensor.py index c43fe461a8e6a1..c771db498536d9 100644 --- a/homeassistant/components/hive/sensor.py +++ b/homeassistant/components/hive/sensor.py @@ -39,7 +39,6 @@ def __init__(self, hivesession, hivedevice): self.session = hivesession self.data_updatesource = f"{self.device_type}.{self.node_id}" self._unique_id = f"{self.node_id}-{self.device_type}" - self.session.entities.append(self) @property def unique_id(self): @@ -51,11 +50,6 @@ def device_info(self): """Return device information.""" return {"identifiers": {(DOMAIN, self.unique_id)}, "name": self.name} - def handle_update(self, updatesource): - """Handle the new update request.""" - if f"{self.device_type}.{self.node_id}" not in updatesource: - self.schedule_update_ha_state() - @property def name(self): """Return the name of the sensor.""" @@ -80,6 +74,17 @@ def icon(self): """Return the icon to use.""" return DEVICETYPE_ICONS.get(self.device_type) + async def async_added_to_hass(self): + """When entity is added to Home Assistant.""" + await super().async_added_to_hass() + self.session.entities.append(self) + self.session.entity_lookup.update({self.entity_id: self.node_id}) + + def handle_update(self, updatesource): + """Handle the new update request.""" + if f"{self.device_type}.{self.node_id}" not in updatesource: + self.schedule_update_ha_state() + def update(self): """Update all Node data from Hive.""" if self.session.core.update_data(self.node_id): diff --git a/homeassistant/components/hive/switch.py b/homeassistant/components/hive/switch.py index 75efdfe3e5d461..236a37dc420035 100644 --- a/homeassistant/components/hive/switch.py +++ b/homeassistant/components/hive/switch.py @@ -25,7 +25,6 @@ def __init__(self, hivesession, hivedevice): self.attributes = {} self.data_updatesource = f"{self.device_type}.{self.node_id}" self._unique_id = f"{self.node_id}-{self.device_type}" - self.session.entities.append(self) @property def unique_id(self): @@ -37,11 +36,6 @@ def device_info(self): """Return device information.""" return {"identifiers": {(DOMAIN, self.unique_id)}, "name": self.name} - def handle_update(self, updatesource): - """Handle the new update request.""" - if f"{self.device_type}.{self.node_id}" not in updatesource: - self.schedule_update_ha_state() - @property def name(self): """Return the name of this Switch device if any.""" @@ -74,6 +68,17 @@ def turn_off(self, **kwargs): for entity in self.session.entities: entity.handle_update(self.data_updatesource) + async def async_added_to_hass(self): + """When entity is added to Home Assistant.""" + await super().async_added_to_hass() + self.session.entities.append(self) + self.session.entity_lookup.update({self.entity_id: self.node_id}) + + def handle_update(self, updatesource): + """Handle the new update request.""" + if f"{self.device_type}.{self.node_id}" not in updatesource: + self.schedule_update_ha_state() + def update(self): """Update all Node data from Hive.""" self.session.core.update_data(self.node_id) diff --git a/homeassistant/components/hive/water_heater.py b/homeassistant/components/hive/water_heater.py index d776f8d078aafe..cd5d4bfe1abc03 100644 --- a/homeassistant/components/hive/water_heater.py +++ b/homeassistant/components/hive/water_heater.py @@ -84,11 +84,6 @@ def supported_features(self): """Return the list of supported features.""" return SUPPORT_FLAGS_HEATER - def handle_update(self, updatesource): - """Handle the new update request.""" - if f"{self.device_type}.{self.node_id}" not in updatesource: - self.schedule_update_ha_state() - @property def name(self): """Return the name of the water heater.""" @@ -111,12 +106,6 @@ def operation_list(self): """List of available operation modes.""" return SUPPORT_WATER_HEATER - async def async_added_to_hass(self): - """When entity is added to Home Assistant.""" - await super().async_added_to_hass() - self.session.entities.append(self) - self.session.entity_lookup.update({self.entity_id: self.node_id}) - def set_operation_mode(self, operation_mode): """Set operation mode.""" new_mode = HASS_TO_HIVE_STATE[operation_mode] @@ -125,6 +114,17 @@ def set_operation_mode(self, operation_mode): for entity in self.session.entities: entity.handle_update(self.data_updatesource) + async def async_added_to_hass(self): + """When entity is added to Home Assistant.""" + await super().async_added_to_hass() + self.session.entities.append(self) + self.session.entity_lookup.update({self.entity_id: self.node_id}) + + def handle_update(self, updatesource): + """Handle the new update request.""" + if f"{self.device_type}.{self.node_id}" not in updatesource: + self.schedule_update_ha_state() + def update(self): """Update all Node data from Hive.""" self.session.core.update_data(self.node_id) From 9576209d621e53e382afae56ea408e799eae4893 Mon Sep 17 00:00:00 2001 From: KJonline Date: Sat, 21 Sep 2019 15:24:20 +0100 Subject: [PATCH 12/26] Update Services --- homeassistant/components/hive/climate.py | 8 ++++---- homeassistant/components/hive/services.yaml | 6 +++--- homeassistant/components/hive/water_heater.py | 13 +++++++------ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/hive/climate.py b/homeassistant/components/hive/climate.py index badd03342892a5..7c0a683f7db44c 100644 --- a/homeassistant/components/hive/climate.py +++ b/homeassistant/components/hive/climate.py @@ -38,7 +38,7 @@ { vol.Required(ATTR_ENTITY_ID): cv.entity_id, vol.Required(ATTR_BOOST_MINUTES): cv.positive_int, - vol.Required(ATTR_TEMPERATURE): cv.string, + vol.Optional(ATTR_TEMPERATURE): cv.string, } ) @@ -59,10 +59,10 @@ def heating_boost(service): """Handle the service call.""" session = hass.data.get(DATA_HIVE) entity = session.entity_lookup[service.data.get(ATTR_ENTITY_ID)] - time = service.data.get(ATTR_BOOST_MINUTES) - temperature = float(service.data.get(ATTR_TEMPERATURE)) + minutes = service.data.get(ATTR_BOOST_MINUTES) + temperature = float(service.data.get(ATTR_TEMPERATURE, 25)) - session.heating.turn_boost_on(entity, time, temperature) + session.heating.turn_boost_on(entity, minutes, temperature) hass.services.register( DOMAIN, SERVICE_BOOST_HEATING, heating_boost, schema=BOOST_HEATING_SCHEMA diff --git a/homeassistant/components/hive/services.yaml b/homeassistant/components/hive/services.yaml index 74d877f9110beb..91f1b1c9157859 100644 --- a/homeassistant/components/hive/services.yaml +++ b/homeassistant/components/hive/services.yaml @@ -4,7 +4,7 @@ boost_heating: fields: entity_id: { - description: Enter the entity_id for the device reuired to set the boost mode., + description: Enter the entity_id for the device required to set the boost mode., example: "climate.heating", } minutes: @@ -21,7 +21,7 @@ boost_hotwater: entity_id: { description: Enter the entity_id for the device reuired to set the boost mode., - example: "water_heater.hotwater", + example: "water_heater.hot_water", } minutes: { description: Set the duration of boost in minutes., example: "90" } - on_off: { description: Set the boost function on or off., example: "on or off" } + on_off: { description: Set the boost function on or off., example: "on" } diff --git a/homeassistant/components/hive/water_heater.py b/homeassistant/components/hive/water_heater.py index cd5d4bfe1abc03..f0971fe8a95e28 100644 --- a/homeassistant/components/hive/water_heater.py +++ b/homeassistant/components/hive/water_heater.py @@ -1,6 +1,6 @@ """Support for hive water heaters.""" import voluptuous as vol -from homeassistant.const import TEMP_CELSIUS, ATTR_ENTITY_ID, ATTR_COMMAND +from homeassistant.const import TEMP_CELSIUS, ATTR_ENTITY_ID import homeassistant.helpers.config_validation as cv from homeassistant.components.water_heater import ( STATE_ECO, @@ -18,11 +18,12 @@ SUPPORT_WATER_HEATER = [STATE_ECO, STATE_ON, STATE_OFF] SERVICE_BOOST_HEATING = "boost_hotwater" ATTR_BOOST_MINUTES = "minutes" +ATTR_MODE = "on_off" BOOST_HOTWATER_SCHEMA = vol.Schema( { vol.Required(ATTR_ENTITY_ID): cv.entity_id, - vol.Required(ATTR_BOOST_MINUTES): cv.positive_int, - vol.Required(ATTR_COMMAND): cv.string, + vol.Optional(ATTR_BOOST_MINUTES): cv.positive_int, + vol.Required(ATTR_MODE): cv.string, } ) @@ -43,11 +44,11 @@ def hotwater_boost(service): """Handle the service call.""" session = hass.data.get(DATA_HIVE) entity = session.entity_lookup[service.data.get(ATTR_ENTITY_ID)] - time = service.data.get(ATTR_BOOST_MINUTES) - mode = service.data.get(ATTR_COMMAND) + minutes = service.data.get(ATTR_BOOST_MINUTES, 30) + mode = service.data.get(ATTR_MODE) if mode == "on": - session.hotwater.turn_boost_on(entity, time) + session.hotwater.turn_boost_on(entity, minutes) elif mode == "off": session.hotwater.turn_boost_off(entity) From 6faac31cbd48664ab8c860e1edd361226d9ab1e3 Mon Sep 17 00:00:00 2001 From: KJonline Date: Sun, 22 Sep 2019 18:39:56 +0100 Subject: [PATCH 13/26] Reviewed Changes --- homeassistant/components/hive/__init__.py | 16 ++++++++- .../components/hive/binary_sensor.py | 12 ------- homeassistant/components/hive/climate.py | 35 +++++++------------ homeassistant/components/hive/light.py | 30 +++++----------- homeassistant/components/hive/sensor.py | 16 +-------- homeassistant/components/hive/services.yaml | 6 ++-- homeassistant/components/hive/switch.py | 20 ++--------- homeassistant/components/hive/water_heater.py | 29 ++++++--------- 8 files changed, 53 insertions(+), 111 deletions(-) diff --git a/homeassistant/components/hive/__init__.py b/homeassistant/components/hive/__init__.py index a416fbb63223b4..bd64f158cb85b2 100644 --- a/homeassistant/components/hive/__init__.py +++ b/homeassistant/components/hive/__init__.py @@ -1,5 +1,6 @@ """Support for the Hive devices.""" import logging +from functools import wraps from pyhiveapi import Pyhiveapi import voluptuous as vol @@ -7,6 +8,8 @@ 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 +from homeassistant.helpers.dispatcher import async_dispatcher_send + _LOGGER = logging.getLogger(__name__) @@ -38,7 +41,6 @@ class HiveSession: """Initiate Hive Session Class.""" - entities = [] entity_lookup = {} core = None heating = None @@ -80,3 +82,15 @@ def setup(hass, config): for hivedevice in devices: load_platform(hass, ha_type, DOMAIN, hivedevice, config) return True + + +def refresh_system(func): + """Force update all entities after state change.""" + + @wraps(func) + async def wrapper(self, *args, **kwargs): + """Call decorated function and send update signal to all entities.""" + await func(self, *args, **kwargs) + async_dispatcher_send(self.hass, DOMAIN) + + return wrapper diff --git a/homeassistant/components/hive/binary_sensor.py b/homeassistant/components/hive/binary_sensor.py index 32a923ba680db4..e86b0850c28b26 100644 --- a/homeassistant/components/hive/binary_sensor.py +++ b/homeassistant/components/hive/binary_sensor.py @@ -26,7 +26,6 @@ def __init__(self, hivesession, hivedevice): self.node_device_type = hivedevice["Hive_DeviceType"] self.session = hivesession self.attributes = {} - self.data_updatesource = f"{self.device_type}.{self.node_id}" self._unique_id = f"{self.node_id}-{self.device_type}" @property @@ -59,17 +58,6 @@ 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) - async def async_added_to_hass(self): - """When entity is added to Home Assistant.""" - await super().async_added_to_hass() - self.session.entities.append(self) - self.session.entity_lookup.update({self.entity_id: self.node_id}) - - def handle_update(self, updatesource): - """Handle the new update request.""" - if f"{self.device_type}.{self.node_id}" not in updatesource: - self.schedule_update_ha_state() - def update(self): """Update all Node data from Hive.""" self.session.core.update_data(self.node_id) diff --git a/homeassistant/components/hive/climate.py b/homeassistant/components/hive/climate.py index 7c0a683f7db44c..6dcecb2d96818e 100644 --- a/homeassistant/components/hive/climate.py +++ b/homeassistant/components/hive/climate.py @@ -15,7 +15,7 @@ from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE, TEMP_CELSIUS import homeassistant.helpers.config_validation as cv -from . import DATA_HIVE, DOMAIN +from . import DATA_HIVE, DOMAIN, refresh_system, HiveSession HIVE_TO_HASS_STATE = { "SCHEDULE": HVAC_MODE_AUTO, @@ -33,11 +33,13 @@ SUPPORT_HVAC = [HVAC_MODE_AUTO, HVAC_MODE_HEAT, HVAC_MODE_OFF] SUPPORT_PRESET = [PRESET_NONE, PRESET_BOOST] SERVICE_BOOST_HEATING = "boost_heating" -ATTR_BOOST_MINUTES = "minutes" +ATTR_TIME_PERIOD = "time_period" BOOST_HEATING_SCHEMA = vol.Schema( { vol.Required(ATTR_ENTITY_ID): cv.entity_id, - vol.Required(ATTR_BOOST_MINUTES): cv.positive_int, + vol.Required(ATTR_TIME_PERIOD): vol.All( + cv.time_period, cv.positive_timedelta, lambda td: td.total_seconds() // 60 + ), vol.Optional(ATTR_TEMPERATURE): cv.string, } ) @@ -55,14 +57,14 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities([climate]) + @refresh_system def heating_boost(service): """Handle the service call.""" - session = hass.data.get(DATA_HIVE) - entity = session.entity_lookup[service.data.get(ATTR_ENTITY_ID)] - minutes = service.data.get(ATTR_BOOST_MINUTES) + node_id = HiveSession.entity_lookup[service.data.get(ATTR_ENTITY_ID)] + minutes = service.data.get(ATTR_TIME_PERIOD) temperature = float(service.data.get(ATTR_TEMPERATURE, 25)) - session.heating.turn_boost_on(entity, minutes, temperature) + session.heating.turn_boost_on(node_id, minutes, temperature) hass.services.register( DOMAIN, SERVICE_BOOST_HEATING, heating_boost, schema=BOOST_HEATING_SCHEMA @@ -80,7 +82,6 @@ def __init__(self, hivesession, hivedevice): self.thermostat_node_id = hivedevice["Thermostat_NodeID"] self.session = hivesession self.attributes = {} - self.data_updatesource = f"{self.device_type}.{self.node_id}" self._unique_id = f"{self.node_id}-{self.device_type}" @property @@ -164,23 +165,20 @@ def preset_modes(self): """Return a list of available preset modes.""" return SUPPORT_PRESET + @refresh_system def set_hvac_mode(self, hvac_mode): """Set new target hvac mode.""" new_mode = HASS_TO_HIVE_STATE[hvac_mode] self.session.heating.set_mode(self.node_id, new_mode) - for entity in self.session.entities: - entity.handle_update(self.data_updatesource) - + @refresh_system def set_temperature(self, **kwargs): """Set new target temperature.""" new_temperature = kwargs.get(ATTR_TEMPERATURE) if new_temperature is not None: self.session.heating.set_target_temperature(self.node_id, new_temperature) - for entity in self.session.entities: - entity.handle_update(self.data_updatesource) - + @refresh_system def set_preset_mode(self, preset_mode) -> None: """Set new preset mode.""" if preset_mode == PRESET_NONE and self.preset_mode == PRESET_BOOST: @@ -193,20 +191,11 @@ def set_preset_mode(self, preset_mode) -> None: self.session.heating.turn_boost_on(self.node_id, 30, temperature) - for entity in self.session.entities: - entity.handle_update(self.data_updatesource) - async def async_added_to_hass(self): """When entity is added to Home Assistant.""" await super().async_added_to_hass() - self.session.entities.append(self) self.session.entity_lookup.update({self.entity_id: self.node_id}) - def handle_update(self, updatesource): - """Handle the new update request.""" - if f"{self.device_type}.{self.node_id}" not in updatesource: - self.schedule_update_ha_state() - def update(self): """Update all Node data from Hive.""" self.session.core.update_data(self.node_id) diff --git a/homeassistant/components/hive/light.py b/homeassistant/components/hive/light.py index 00dfaf178e78be..d9a1248c3582c4 100644 --- a/homeassistant/components/hive/light.py +++ b/homeassistant/components/hive/light.py @@ -10,7 +10,7 @@ ) import homeassistant.util.color as color_util -from . import DATA_HIVE, DOMAIN +from . import DATA_HIVE, DOMAIN, refresh_system def setup_platform(hass, config, add_entities, discovery_info=None): @@ -33,7 +33,6 @@ def __init__(self, hivesession, hivedevice): self.light_device_type = hivedevice["Hive_Light_DeviceType"] self.session = hivesession self.attributes = {} - self.data_updatesource = f"{self.device_type}.{self.node_id}" self._unique_id = f"{self.node_id}-{self.device_type}" @property @@ -100,6 +99,7 @@ def is_on(self): """Return true if light is on.""" return self.session.light.get_state(self.node_id) + @refresh_system def turn_on(self, **kwargs): """Instruct the light to turn on.""" new_brightness = None @@ -128,14 +128,10 @@ def turn_on(self, **kwargs): new_color, ) - for entity in self.session.entities: - entity.handle_update(self.data_updatesource) - + @refresh_system def turn_off(self, **kwargs): """Instruct the light to turn off.""" self.session.light.turn_off(self.node_id) - for entity in self.session.entities: - entity.handle_update(self.data_updatesource) @property def supported_features(self): @@ -150,18 +146,8 @@ def supported_features(self): return supported_features - async def async_added_to_hass(self): - """When entity is added to Home Assistant.""" - await super().async_added_to_hass() - self.session.entities.append(self) - self.session.entity_lookup.update({self.entity_id: self.node_id}) - - def handle_update(self, updatesource): - """Handle the new update request.""" - if f"{self.device_type}.{self.node_id}" not in updatesource: - self.schedule_update_ha_state() - - def update(self): - """Update all Node data from Hive.""" - self.session.core.update_data(self.node_id) - self.attributes = self.session.attributes.state_attributes(self.node_id) + +def update(self): + """Update all Node data from Hive.""" + self.session.core.update_data(self.node_id) + self.attributes = self.session.attributes.state_attributes(self.node_id) diff --git a/homeassistant/components/hive/sensor.py b/homeassistant/components/hive/sensor.py index c771db498536d9..3f379f0d680293 100644 --- a/homeassistant/components/hive/sensor.py +++ b/homeassistant/components/hive/sensor.py @@ -37,7 +37,6 @@ def __init__(self, hivesession, hivedevice): self.device_type = hivedevice["HA_DeviceType"] self.node_device_type = hivedevice["Hive_DeviceType"] self.session = hivesession - self.data_updatesource = f"{self.device_type}.{self.node_id}" self._unique_id = f"{self.node_id}-{self.device_type}" @property @@ -74,19 +73,6 @@ def icon(self): """Return the icon to use.""" return DEVICETYPE_ICONS.get(self.device_type) - async def async_added_to_hass(self): - """When entity is added to Home Assistant.""" - await super().async_added_to_hass() - self.session.entities.append(self) - self.session.entity_lookup.update({self.entity_id: self.node_id}) - - def handle_update(self, updatesource): - """Handle the new update request.""" - if f"{self.device_type}.{self.node_id}" not in updatesource: - self.schedule_update_ha_state() - def update(self): """Update all Node data from Hive.""" - if self.session.core.update_data(self.node_id): - for entity in self.session.entities: - entity.handle_update(self.data_updatesource) + self.session.core.update_data(self.node_id) diff --git a/homeassistant/components/hive/services.yaml b/homeassistant/components/hive/services.yaml index 91f1b1c9157859..27d7acfc83bab0 100644 --- a/homeassistant/components/hive/services.yaml +++ b/homeassistant/components/hive/services.yaml @@ -7,8 +7,8 @@ boost_heating: description: Enter the entity_id for the device required to set the boost mode., example: "climate.heating", } - minutes: - { description: Set the duration of boost in minutes., example: "90" } + time_period: + { description: Set the time period for the boost., example: "01:30:00" } temperature: { description: Set the target temperature for the boost period., @@ -23,5 +23,5 @@ boost_hotwater: description: Enter the entity_id for the device reuired to set the boost mode., example: "water_heater.hot_water", } - minutes: { description: Set the duration of boost in minutes., example: "90" } + time_period: { description: Set the time period for the boost., example: "01:30:00" } on_off: { description: Set the boost function on or off., example: "on" } diff --git a/homeassistant/components/hive/switch.py b/homeassistant/components/hive/switch.py index 236a37dc420035..88fab78b03d210 100644 --- a/homeassistant/components/hive/switch.py +++ b/homeassistant/components/hive/switch.py @@ -1,7 +1,7 @@ """Support for the Hive switches.""" from homeassistant.components.switch import SwitchDevice -from . import DATA_HIVE, DOMAIN +from . import DATA_HIVE, DOMAIN, refresh_system def setup_platform(hass, config, add_entities, discovery_info=None): @@ -23,7 +23,6 @@ def __init__(self, hivesession, hivedevice): self.device_type = hivedevice["HA_DeviceType"] self.session = hivesession self.attributes = {} - self.data_updatesource = f"{self.device_type}.{self.node_id}" self._unique_id = f"{self.node_id}-{self.device_type}" @property @@ -56,28 +55,15 @@ def is_on(self): """Return true if switch is on.""" return self.session.switch.get_state(self.node_id) + @refresh_system def turn_on(self, **kwargs): """Turn the switch on.""" self.session.switch.turn_on(self.node_id) - for entity in self.session.entities: - entity.handle_update(self.data_updatesource) + @refresh_system def turn_off(self, **kwargs): """Turn the device off.""" self.session.switch.turn_off(self.node_id) - for entity in self.session.entities: - entity.handle_update(self.data_updatesource) - - async def async_added_to_hass(self): - """When entity is added to Home Assistant.""" - await super().async_added_to_hass() - self.session.entities.append(self) - self.session.entity_lookup.update({self.entity_id: self.node_id}) - - def handle_update(self, updatesource): - """Handle the new update request.""" - if f"{self.device_type}.{self.node_id}" not in updatesource: - self.schedule_update_ha_state() def update(self): """Update all Node data from Hive.""" diff --git a/homeassistant/components/hive/water_heater.py b/homeassistant/components/hive/water_heater.py index f0971fe8a95e28..66dac43862767d 100644 --- a/homeassistant/components/hive/water_heater.py +++ b/homeassistant/components/hive/water_heater.py @@ -9,7 +9,7 @@ SUPPORT_OPERATION_MODE, WaterHeaterDevice, ) -from . import DATA_HIVE, DOMAIN +from . import DATA_HIVE, DOMAIN, refresh_system, HiveSession SUPPORT_FLAGS_HEATER = SUPPORT_OPERATION_MODE @@ -17,12 +17,14 @@ HASS_TO_HIVE_STATE = {STATE_ECO: "SCHEDULE", STATE_ON: "ON", STATE_OFF: "OFF"} SUPPORT_WATER_HEATER = [STATE_ECO, STATE_ON, STATE_OFF] SERVICE_BOOST_HEATING = "boost_hotwater" -ATTR_BOOST_MINUTES = "minutes" +ATTR_TIME_PERIOD = "time_period" ATTR_MODE = "on_off" BOOST_HOTWATER_SCHEMA = vol.Schema( { vol.Required(ATTR_ENTITY_ID): cv.entity_id, - vol.Optional(ATTR_BOOST_MINUTES): cv.positive_int, + vol.Optional(ATTR_TIME_PERIOD): vol.All( + cv.time_period, cv.positive_timedelta, lambda td: td.total_seconds() // 60 + ), vol.Required(ATTR_MODE): cv.string, } ) @@ -40,17 +42,17 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities([water_heater]) + @refresh_system def hotwater_boost(service): """Handle the service call.""" - session = hass.data.get(DATA_HIVE) - entity = session.entity_lookup[service.data.get(ATTR_ENTITY_ID)] - minutes = service.data.get(ATTR_BOOST_MINUTES, 30) + node_id = HiveSession.entity_lookup[service.data.get(ATTR_ENTITY_ID)] + minutes = service.data.get(ATTR_TIME_PERIOD, 30) mode = service.data.get(ATTR_MODE) if mode == "on": - session.hotwater.turn_boost_on(entity, minutes) + session.hotwater.turn_boost_on(node_id, minutes) elif mode == "off": - session.hotwater.turn_boost_off(entity) + session.hotwater.turn_boost_off(node_id) hass.services.register( DOMAIN, SERVICE_BOOST_HEATING, hotwater_boost, schema=BOOST_HOTWATER_SCHEMA @@ -66,7 +68,6 @@ def __init__(self, hivesession, hivedevice): self.node_name = hivedevice["Hive_NodeName"] self.device_type = hivedevice["HA_DeviceType"] self.session = hivesession - self.data_updatesource = f"{self.device_type}.{self.node_id}" self._unique_id = f"{self.node_id}-{self.device_type}" self._unit_of_measurement = TEMP_CELSIUS @@ -107,25 +108,17 @@ def operation_list(self): """List of available operation modes.""" return SUPPORT_WATER_HEATER + @refresh_system def set_operation_mode(self, operation_mode): """Set operation mode.""" new_mode = HASS_TO_HIVE_STATE[operation_mode] self.session.hotwater.set_mode(self.node_id, new_mode) - for entity in self.session.entities: - entity.handle_update(self.data_updatesource) - async def async_added_to_hass(self): """When entity is added to Home Assistant.""" await super().async_added_to_hass() - self.session.entities.append(self) self.session.entity_lookup.update({self.entity_id: self.node_id}) - def handle_update(self, updatesource): - """Handle the new update request.""" - if f"{self.device_type}.{self.node_id}" not in updatesource: - self.schedule_update_ha_state() - def update(self): """Update all Node data from Hive.""" self.session.core.update_data(self.node_id) From b7c5d858d604865ba460ad599e54baebb4ef4428 Mon Sep 17 00:00:00 2001 From: KJonline Date: Sun, 22 Sep 2019 21:46:42 +0100 Subject: [PATCH 14/26] Fixed Refresh System --- homeassistant/components/hive/__init__.py | 4 ++-- homeassistant/components/hive/climate.py | 1 - homeassistant/components/hive/water_heater.py | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/hive/__init__.py b/homeassistant/components/hive/__init__.py index bd64f158cb85b2..fc610ba9639373 100644 --- a/homeassistant/components/hive/__init__.py +++ b/homeassistant/components/hive/__init__.py @@ -88,9 +88,9 @@ def refresh_system(func): """Force update all entities after state change.""" @wraps(func) - async def wrapper(self, *args, **kwargs): + def wrapper(self, *args, **kwargs): """Call decorated function and send update signal to all entities.""" - await func(self, *args, **kwargs) + func(self, *args, **kwargs) async_dispatcher_send(self.hass, DOMAIN) return wrapper diff --git a/homeassistant/components/hive/climate.py b/homeassistant/components/hive/climate.py index 6dcecb2d96818e..a6d1d6a34d1840 100644 --- a/homeassistant/components/hive/climate.py +++ b/homeassistant/components/hive/climate.py @@ -57,7 +57,6 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities([climate]) - @refresh_system def heating_boost(service): """Handle the service call.""" node_id = HiveSession.entity_lookup[service.data.get(ATTR_ENTITY_ID)] diff --git a/homeassistant/components/hive/water_heater.py b/homeassistant/components/hive/water_heater.py index 66dac43862767d..e515a7a9b6de7c 100644 --- a/homeassistant/components/hive/water_heater.py +++ b/homeassistant/components/hive/water_heater.py @@ -42,7 +42,6 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities([water_heater]) - @refresh_system def hotwater_boost(service): """Handle the service call.""" node_id = HiveSession.entity_lookup[service.data.get(ATTR_ENTITY_ID)] From aad3aadf9ebb2c14a9f9e9d7e482e2172ded6af0 Mon Sep 17 00:00:00 2001 From: KJonline Date: Sun, 22 Sep 2019 23:03:12 +0100 Subject: [PATCH 15/26] Review 2 --- homeassistant/components/hive/__init__.py | 5 ++-- homeassistant/components/hive/climate.py | 20 +++++++++---- homeassistant/components/hive/water_heater.py | 29 +++++++++++++------ 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/hive/__init__.py b/homeassistant/components/hive/__init__.py index fc610ba9639373..b696a0158ad99a 100644 --- a/homeassistant/components/hive/__init__.py +++ b/homeassistant/components/hive/__init__.py @@ -8,7 +8,7 @@ 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 -from homeassistant.helpers.dispatcher import async_dispatcher_send +from homeassistant.helpers.dispatcher import dispatcher_send _LOGGER = logging.getLogger(__name__) @@ -89,8 +89,7 @@ def refresh_system(func): @wraps(func) def wrapper(self, *args, **kwargs): - """Call decorated function and send update signal to all entities.""" func(self, *args, **kwargs) - async_dispatcher_send(self.hass, DOMAIN) + dispatcher_send(self.hass, DOMAIN) return wrapper diff --git a/homeassistant/components/hive/climate.py b/homeassistant/components/hive/climate.py index a6d1d6a34d1840..3b330b5b444451 100644 --- a/homeassistant/components/hive/climate.py +++ b/homeassistant/components/hive/climate.py @@ -1,4 +1,5 @@ """Support for the Hive climate devices.""" +import logging import voluptuous as vol @@ -15,7 +16,7 @@ from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE, TEMP_CELSIUS import homeassistant.helpers.config_validation as cv -from . import DATA_HIVE, DOMAIN, refresh_system, HiveSession +from . import DATA_HIVE, DOMAIN, HiveSession, refresh_system HIVE_TO_HASS_STATE = { "SCHEDULE": HVAC_MODE_AUTO, @@ -40,10 +41,12 @@ vol.Required(ATTR_TIME_PERIOD): vol.All( cv.time_period, cv.positive_timedelta, lambda td: td.total_seconds() // 60 ), - vol.Optional(ATTR_TEMPERATURE): cv.string, + vol.Optional(ATTR_TEMPERATURE, default="25.0"): cv.string, } ) +_LOGGER = logging.getLogger(__name__) + def setup_platform(hass, config, add_entities, discovery_info=None): """Set up Hive climate devices.""" @@ -59,9 +62,14 @@ def setup_platform(hass, config, add_entities, discovery_info=None): def heating_boost(service): """Handle the service call.""" - node_id = HiveSession.entity_lookup[service.data.get(ATTR_ENTITY_ID)] - minutes = service.data.get(ATTR_TIME_PERIOD) - temperature = float(service.data.get(ATTR_TEMPERATURE, 25)) + node_id = HiveSession.entity_lookup.get(service.data[ATTR_ENTITY_ID]) + if not node_id: + # log or raise error + _LOGGER.error("Cannot boost entity id entered.") + return + + minutes = service.data[ATTR_TIME_PERIOD] + temperature = service.data.get(ATTR_TEMPERATURE) session.heating.turn_boost_on(node_id, minutes, temperature) @@ -193,7 +201,7 @@ def set_preset_mode(self, preset_mode) -> None: async def async_added_to_hass(self): """When entity is added to Home Assistant.""" await super().async_added_to_hass() - self.session.entity_lookup.update({self.entity_id: self.node_id}) + self.session.entity_lookup[self.entity_id] = self.node_id def update(self): """Update all Node data from Hive.""" diff --git a/homeassistant/components/hive/water_heater.py b/homeassistant/components/hive/water_heater.py index e515a7a9b6de7c..7c25797deed276 100644 --- a/homeassistant/components/hive/water_heater.py +++ b/homeassistant/components/hive/water_heater.py @@ -1,15 +1,19 @@ """Support for hive water heaters.""" +import logging + import voluptuous as vol -from homeassistant.const import TEMP_CELSIUS, ATTR_ENTITY_ID -import homeassistant.helpers.config_validation as cv + from homeassistant.components.water_heater import ( STATE_ECO, - STATE_ON, STATE_OFF, + STATE_ON, SUPPORT_OPERATION_MODE, WaterHeaterDevice, ) -from . import DATA_HIVE, DOMAIN, refresh_system, HiveSession +from homeassistant.const import ATTR_ENTITY_ID, TEMP_CELSIUS +import homeassistant.helpers.config_validation as cv + +from . import DATA_HIVE, DOMAIN, HiveSession, refresh_system SUPPORT_FLAGS_HEATER = SUPPORT_OPERATION_MODE @@ -22,7 +26,7 @@ BOOST_HOTWATER_SCHEMA = vol.Schema( { vol.Required(ATTR_ENTITY_ID): cv.entity_id, - vol.Optional(ATTR_TIME_PERIOD): vol.All( + vol.Optional(ATTR_TIME_PERIOD, default="00:30:00"): vol.All( cv.time_period, cv.positive_timedelta, lambda td: td.total_seconds() // 60 ), vol.Required(ATTR_MODE): cv.string, @@ -30,6 +34,9 @@ ) +_LOGGER = logging.getLogger(__name__) + + def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Hive water heater devices.""" if discovery_info is None: @@ -44,9 +51,13 @@ def setup_platform(hass, config, add_entities, discovery_info=None): def hotwater_boost(service): """Handle the service call.""" - node_id = HiveSession.entity_lookup[service.data.get(ATTR_ENTITY_ID)] - minutes = service.data.get(ATTR_TIME_PERIOD, 30) - mode = service.data.get(ATTR_MODE) + node_id = HiveSession.entity_lookup.get(service.data[ATTR_ENTITY_ID]) + if not node_id: + # log or raise error + _LOGGER.error("Cannot boost entity id entered.") + return + minutes = service.data.get(ATTR_TIME_PERIOD) + mode = service.data[ATTR_MODE] if mode == "on": session.hotwater.turn_boost_on(node_id, minutes) @@ -116,7 +127,7 @@ def set_operation_mode(self, operation_mode): async def async_added_to_hass(self): """When entity is added to Home Assistant.""" await super().async_added_to_hass() - self.session.entity_lookup.update({self.entity_id: self.node_id}) + self.session.entity_lookup[self.entity_id] = self.node_id def update(self): """Update all Node data from Hive.""" From d4db7669c4612fd4450c0bdb59bec120c7a5cb86 Mon Sep 17 00:00:00 2001 From: KJonline Date: Mon, 23 Sep 2019 21:28:15 +0100 Subject: [PATCH 16/26] Moved device iteration to the platform --- homeassistant/components/hive/__init__.py | 92 +++++++++++++++++-- .../components/hive/binary_sensor.py | 7 +- homeassistant/components/hive/climate.py | 57 +++--------- homeassistant/components/hive/light.py | 7 +- homeassistant/components/hive/sensor.py | 12 +-- homeassistant/components/hive/switch.py | 7 +- homeassistant/components/hive/water_heater.py | 57 +++--------- 7 files changed, 123 insertions(+), 116 deletions(-) diff --git a/homeassistant/components/hive/__init__.py b/homeassistant/components/hive/__init__.py index b696a0158ad99a..75c5b19a5cd2ac 100644 --- a/homeassistant/components/hive/__init__.py +++ b/homeassistant/components/hive/__init__.py @@ -1,20 +1,29 @@ """Support for the Hive devices.""" -import logging from functools import wraps +import logging from pyhiveapi import Pyhiveapi import voluptuous as vol -from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME +from homeassistant.const import ( + CONF_PASSWORD, + CONF_SCAN_INTERVAL, + CONF_USERNAME, + ATTR_ENTITY_ID, + ATTR_TEMPERATURE, +) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.discovery import load_platform from homeassistant.helpers.dispatcher import dispatcher_send - _LOGGER = logging.getLogger(__name__) DOMAIN = "hive" DATA_HIVE = "data_hive" +SERVICE_BOOST_HOTWATER = "boost_hotwater" +SERVICE_BOOST_HEATING = "boost_heating" +ATTR_TIME_PERIOD = "time_period" +ATTR_MODE = "on_off" DEVICETYPES = { "binary_sensor": "device_list_binary_sensor", "climate": "device_list_climate", @@ -37,6 +46,26 @@ extra=vol.ALLOW_EXTRA, ) +BOOST_HEATING_SCHEMA = vol.Schema( + { + vol.Required(ATTR_ENTITY_ID): cv.entity_id, + vol.Required(ATTR_TIME_PERIOD): vol.All( + cv.time_period, cv.positive_timedelta, lambda td: td.total_seconds() // 60 + ), + vol.Optional(ATTR_TEMPERATURE, default="25.0"): vol.Coerce(float), + } +) + +BOOST_HOTWATER_SCHEMA = vol.Schema( + { + vol.Required(ATTR_ENTITY_ID): cv.entity_id, + vol.Optional(ATTR_TIME_PERIOD, default="00:30:00"): vol.All( + cv.time_period, cv.positive_timedelta, lambda td: td.total_seconds() // 60 + ), + vol.Required(ATTR_MODE): cv.string, + } +) + class HiveSession: """Initiate Hive Session Class.""" @@ -54,6 +83,35 @@ class HiveSession: def setup(hass, config): """Set up the Hive Component.""" + + def heating_boost(service): + """Handle the service call.""" + node_id = HiveSession.entity_lookup.get(service.data[ATTR_ENTITY_ID]) + if not node_id: + # log or raise error + _LOGGER.error("Cannot boost entity id entered.") + return + + minutes = service.data[ATTR_TIME_PERIOD] + temperature = service.data.get(ATTR_TEMPERATURE) + + session.heating.turn_boost_on(node_id, minutes, temperature) + + def hotwater_boost(service): + """Handle the service call.""" + node_id = HiveSession.entity_lookup.get(service.data[ATTR_ENTITY_ID]) + if not node_id: + # log or raise error + _LOGGER.error("Cannot boost entity id entered.") + return + minutes = service.data.get(ATTR_TIME_PERIOD) + mode = service.data[ATTR_MODE] + + if mode == "on": + session.hotwater.turn_boost_on(node_id, minutes) + elif mode == "off": + session.hotwater.turn_boost_off(node_id) + session = HiveSession() session.core = Pyhiveapi() @@ -61,9 +119,9 @@ def setup(hass, config): password = config[DOMAIN][CONF_PASSWORD] update_interval = config[DOMAIN][CONF_SCAN_INTERVAL] - devicelist = session.core.initialise_api(username, password, update_interval) + devices = session.core.initialise_api(username, password, update_interval) - if devicelist is None: + if devices is None: _LOGGER.error("Hive API initialization failed") return False @@ -76,11 +134,25 @@ def setup(hass, config): session.attributes = Pyhiveapi.Attributes() 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) + for ha_type in DEVICETYPES: + devicelist = devices.get(DEVICETYPES[ha_type], None) + if devicelist: + load_platform(hass, ha_type, DOMAIN, devicelist, config) + if ha_type == "climate": + hass.services.register( + DOMAIN, + SERVICE_BOOST_HEATING, + heating_boost, + schema=BOOST_HEATING_SCHEMA, + ) + if ha_type == "water_heater": + hass.services.register( + DOMAIN, + SERVICE_BOOST_HEATING, + hotwater_boost, + schema=BOOST_HOTWATER_SCHEMA, + ) + return True diff --git a/homeassistant/components/hive/binary_sensor.py b/homeassistant/components/hive/binary_sensor.py index e86b0850c28b26..a61b125d2f0009 100644 --- a/homeassistant/components/hive/binary_sensor.py +++ b/homeassistant/components/hive/binary_sensor.py @@ -1,7 +1,7 @@ """Support for the Hive binary sensors.""" from homeassistant.components.binary_sensor import BinarySensorDevice -from . import DATA_HIVE, DOMAIN +from . import DOMAIN, DATA_HIVE DEVICETYPE_DEVICE_CLASS = {"motionsensor": "motion", "contactsensor": "opening"} @@ -10,9 +10,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None): """Set up Hive sensor devices.""" if discovery_info is None: return - session = hass.data.get(DATA_HIVE) - add_entities([HiveBinarySensorEntity(session, discovery_info)]) + session = hass.data.get(DATA_HIVE) + for device in discovery_info: + add_entities([HiveBinarySensorEntity(session, device)]) class HiveBinarySensorEntity(BinarySensorDevice): diff --git a/homeassistant/components/hive/climate.py b/homeassistant/components/hive/climate.py index 3b330b5b444451..5e526396dd2dff 100644 --- a/homeassistant/components/hive/climate.py +++ b/homeassistant/components/hive/climate.py @@ -1,8 +1,4 @@ """Support for the Hive climate devices.""" -import logging - -import voluptuous as vol - from homeassistant.components.climate import ClimateDevice from homeassistant.components.climate.const import ( HVAC_MODE_AUTO, @@ -13,10 +9,11 @@ SUPPORT_PRESET_MODE, SUPPORT_TARGET_TEMPERATURE, ) -from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE, TEMP_CELSIUS -import homeassistant.helpers.config_validation as cv +from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS -from . import DATA_HIVE, DOMAIN, HiveSession, refresh_system +# from homeassistant.helpers.dispatcher import dispatcher_connect + +from . import DOMAIN, DATA_HIVE, refresh_system HIVE_TO_HASS_STATE = { "SCHEDULE": HVAC_MODE_AUTO, @@ -33,49 +30,16 @@ SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE SUPPORT_HVAC = [HVAC_MODE_AUTO, HVAC_MODE_HEAT, HVAC_MODE_OFF] SUPPORT_PRESET = [PRESET_NONE, PRESET_BOOST] -SERVICE_BOOST_HEATING = "boost_heating" -ATTR_TIME_PERIOD = "time_period" -BOOST_HEATING_SCHEMA = vol.Schema( - { - vol.Required(ATTR_ENTITY_ID): cv.entity_id, - vol.Required(ATTR_TIME_PERIOD): vol.All( - cv.time_period, cv.positive_timedelta, lambda td: td.total_seconds() // 60 - ), - vol.Optional(ATTR_TEMPERATURE, default="25.0"): cv.string, - } -) - -_LOGGER = logging.getLogger(__name__) def setup_platform(hass, config, add_entities, discovery_info=None): """Set up Hive climate devices.""" if discovery_info is None: return - if discovery_info["HA_DeviceType"] != "Heating": - return session = hass.data.get(DATA_HIVE) - climate = HiveClimateEntity(session, discovery_info) - - add_entities([climate]) - - def heating_boost(service): - """Handle the service call.""" - node_id = HiveSession.entity_lookup.get(service.data[ATTR_ENTITY_ID]) - if not node_id: - # log or raise error - _LOGGER.error("Cannot boost entity id entered.") - return - - minutes = service.data[ATTR_TIME_PERIOD] - temperature = service.data.get(ATTR_TEMPERATURE) - - session.heating.turn_boost_on(node_id, minutes, temperature) - - hass.services.register( - DOMAIN, SERVICE_BOOST_HEATING, heating_boost, schema=BOOST_HEATING_SCHEMA - ) + for device in discovery_info: + add_entities([HiveClimateEntity(session, device)]) class HiveClimateEntity(ClimateDevice): @@ -186,7 +150,7 @@ def set_temperature(self, **kwargs): self.session.heating.set_target_temperature(self.node_id, new_temperature) @refresh_system - def set_preset_mode(self, preset_mode) -> None: + def set_preset_mode(self, preset_mode): """Set new preset mode.""" if preset_mode == PRESET_NONE and self.preset_mode == PRESET_BOOST: self.session.heating.turn_boost_off(self.node_id) @@ -195,7 +159,6 @@ def set_preset_mode(self, preset_mode) -> None: curtemp = self.session.heating.current_temperature(self.node_id) curtemp = round(curtemp * 2) / 2 temperature = curtemp + 0.5 - self.session.heating.turn_boost_on(self.node_id, 30, temperature) async def async_added_to_hass(self): @@ -203,6 +166,12 @@ async def async_added_to_hass(self): await super().async_added_to_hass() self.session.entity_lookup[self.entity_id] = self.node_id + # dispatcher_connect(self.hass, DOMAIN, self._update_callback) + + # def _update_callback(self): + # """Call update method.""" + # self.schedule_update_ha_state(False) + def update(self): """Update all Node data from Hive.""" self.session.core.update_data(self.node_id) diff --git a/homeassistant/components/hive/light.py b/homeassistant/components/hive/light.py index d9a1248c3582c4..344b1eea2eaeeb 100644 --- a/homeassistant/components/hive/light.py +++ b/homeassistant/components/hive/light.py @@ -10,16 +10,17 @@ ) import homeassistant.util.color as color_util -from . import DATA_HIVE, DOMAIN, refresh_system +from . import DOMAIN, DATA_HIVE, refresh_system def setup_platform(hass, config, add_entities, discovery_info=None): """Set up Hive light devices.""" if discovery_info is None: return - session = hass.data.get(DATA_HIVE) - add_entities([HiveDeviceLight(session, discovery_info)]) + session = hass.data.get(DATA_HIVE) + for device in discovery_info: + add_entities([HiveDeviceLight(session, device)]) class HiveDeviceLight(Light): diff --git a/homeassistant/components/hive/sensor.py b/homeassistant/components/hive/sensor.py index 3f379f0d680293..9c751e87247e67 100644 --- a/homeassistant/components/hive/sensor.py +++ b/homeassistant/components/hive/sensor.py @@ -2,7 +2,7 @@ from homeassistant.const import TEMP_CELSIUS from homeassistant.helpers.entity import Entity -from . import DATA_HIVE, DOMAIN +from . import DOMAIN, DATA_HIVE FRIENDLY_NAMES = { "Hub_OnlineStatus": "Hive Hub Status", @@ -19,13 +19,11 @@ def setup_platform(hass, config, add_entities, discovery_info=None): """Set up Hive sensor devices.""" if discovery_info is None: return - session = hass.data.get(DATA_HIVE) - if ( - discovery_info["HA_DeviceType"] == "Hub_OnlineStatus" - or discovery_info["HA_DeviceType"] == "Hive_OutsideTemperature" - ): - add_entities([HiveSensorEntity(session, discovery_info)]) + session = hass.data.get(DATA_HIVE) + for device in discovery_info: + if device["HA_DeviceType"] in FRIENDLY_NAMES: + add_entities([HiveSensorEntity(session, device)]) class HiveSensorEntity(Entity): diff --git a/homeassistant/components/hive/switch.py b/homeassistant/components/hive/switch.py index 88fab78b03d210..9d6c6d238444c5 100644 --- a/homeassistant/components/hive/switch.py +++ b/homeassistant/components/hive/switch.py @@ -1,16 +1,17 @@ """Support for the Hive switches.""" from homeassistant.components.switch import SwitchDevice -from . import DATA_HIVE, DOMAIN, refresh_system +from . import DOMAIN, DATA_HIVE, refresh_system def setup_platform(hass, config, add_entities, discovery_info=None): """Set up Hive switches.""" if discovery_info is None: return - session = hass.data.get(DATA_HIVE) - add_entities([HiveDevicePlug(session, discovery_info)]) + session = hass.data.get(DATA_HIVE) + for device in discovery_info: + add_entities([HiveDevicePlug(session, device)]) class HiveDevicePlug(SwitchDevice): diff --git a/homeassistant/components/hive/water_heater.py b/homeassistant/components/hive/water_heater.py index 7c25797deed276..ed187331b9d404 100644 --- a/homeassistant/components/hive/water_heater.py +++ b/homeassistant/components/hive/water_heater.py @@ -1,8 +1,4 @@ """Support for hive water heaters.""" -import logging - -import voluptuous as vol - from homeassistant.components.water_heater import ( STATE_ECO, STATE_OFF, @@ -10,63 +6,27 @@ SUPPORT_OPERATION_MODE, WaterHeaterDevice, ) -from homeassistant.const import ATTR_ENTITY_ID, TEMP_CELSIUS -import homeassistant.helpers.config_validation as cv +from homeassistant.const import TEMP_CELSIUS +from homeassistant.core import callback +from homeassistant.helpers.dispatcher import dispatcher_connect -from . import DATA_HIVE, DOMAIN, HiveSession, refresh_system +from . import DOMAIN, DATA_HIVE, refresh_system SUPPORT_FLAGS_HEATER = SUPPORT_OPERATION_MODE HIVE_TO_HASS_STATE = {"SCHEDULE": STATE_ECO, "ON": STATE_ON, "OFF": STATE_OFF} HASS_TO_HIVE_STATE = {STATE_ECO: "SCHEDULE", STATE_ON: "ON", STATE_OFF: "OFF"} SUPPORT_WATER_HEATER = [STATE_ECO, STATE_ON, STATE_OFF] -SERVICE_BOOST_HEATING = "boost_hotwater" -ATTR_TIME_PERIOD = "time_period" -ATTR_MODE = "on_off" -BOOST_HOTWATER_SCHEMA = vol.Schema( - { - vol.Required(ATTR_ENTITY_ID): cv.entity_id, - vol.Optional(ATTR_TIME_PERIOD, default="00:30:00"): vol.All( - cv.time_period, cv.positive_timedelta, lambda td: td.total_seconds() // 60 - ), - vol.Required(ATTR_MODE): cv.string, - } -) - - -_LOGGER = logging.getLogger(__name__) def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Hive water heater devices.""" if discovery_info is None: return - if discovery_info["HA_DeviceType"] != "HotWater": - return session = hass.data.get(DATA_HIVE) - water_heater = HiveWaterHeater(session, discovery_info) - - add_entities([water_heater]) - - def hotwater_boost(service): - """Handle the service call.""" - node_id = HiveSession.entity_lookup.get(service.data[ATTR_ENTITY_ID]) - if not node_id: - # log or raise error - _LOGGER.error("Cannot boost entity id entered.") - return - minutes = service.data.get(ATTR_TIME_PERIOD) - mode = service.data[ATTR_MODE] - - if mode == "on": - session.hotwater.turn_boost_on(node_id, minutes) - elif mode == "off": - session.hotwater.turn_boost_off(node_id) - - hass.services.register( - DOMAIN, SERVICE_BOOST_HEATING, hotwater_boost, schema=BOOST_HOTWATER_SCHEMA - ) + for device in discovery_info: + add_entities([HiveWaterHeater(session, device)]) class HiveWaterHeater(WaterHeaterDevice): @@ -128,6 +88,11 @@ async def async_added_to_hass(self): """When entity is added to Home Assistant.""" await super().async_added_to_hass() self.session.entity_lookup[self.entity_id] = self.node_id + dispatcher_connect(self.hass, DOMAIN, self._update_callback) + + @callback + def _update_callback(self) -> None: + self.schedule_update_ha_state() def update(self): """Update all Node data from Hive.""" From aa92c41edfd89755d9410eec8fc96f58dffb097f Mon Sep 17 00:00:00 2001 From: KJonline Date: Mon, 23 Sep 2019 21:37:16 +0100 Subject: [PATCH 17/26] update --- homeassistant/components/hive/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/hive/__init__.py b/homeassistant/components/hive/__init__.py index 75c5b19a5cd2ac..5c425b85f7af8b 100644 --- a/homeassistant/components/hive/__init__.py +++ b/homeassistant/components/hive/__init__.py @@ -1,4 +1,4 @@ -"""Support for the Hive devices.""" +"""Support for the Hive devices and services.""" from functools import wraps import logging From adcd69c48b6f8ab5f8cc4f0cf89b706c687a07ab Mon Sep 17 00:00:00 2001 From: Khole Jones Date: Tue, 24 Sep 2019 09:03:14 +0100 Subject: [PATCH 18/26] Updates #2 --- homeassistant/components/hive/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/hive/__init__.py b/homeassistant/components/hive/__init__.py index 5c425b85f7af8b..ee394613125c38 100644 --- a/homeassistant/components/hive/__init__.py +++ b/homeassistant/components/hive/__init__.py @@ -89,11 +89,11 @@ def heating_boost(service): node_id = HiveSession.entity_lookup.get(service.data[ATTR_ENTITY_ID]) if not node_id: # log or raise error - _LOGGER.error("Cannot boost entity id entered.") + _LOGGER.error("Cannot boost entity id entered") return minutes = service.data[ATTR_TIME_PERIOD] - temperature = service.data.get(ATTR_TEMPERATURE) + temperature = service.data[ATTR_TEMPERATURE] session.heating.turn_boost_on(node_id, minutes, temperature) @@ -102,9 +102,9 @@ def hotwater_boost(service): node_id = HiveSession.entity_lookup.get(service.data[ATTR_ENTITY_ID]) if not node_id: # log or raise error - _LOGGER.error("Cannot boost entity id entered.") + _LOGGER.error("Cannot boost entity id entered") return - minutes = service.data.get(ATTR_TIME_PERIOD) + minutes = service.data.[ATTR_TIME_PERIOD] mode = service.data[ATTR_MODE] if mode == "on": @@ -135,7 +135,7 @@ def hotwater_boost(service): hass.data[DATA_HIVE] = session for ha_type in DEVICETYPES: - devicelist = devices.get(DEVICETYPES[ha_type], None) + devicelist = devices.get(DEVICETYPES[ha_type]) if devicelist: load_platform(hass, ha_type, DOMAIN, devicelist, config) if ha_type == "climate": From 4922ae462a9860feff4d8205f977f68d95a175f3 Mon Sep 17 00:00:00 2001 From: KJonline Date: Tue, 24 Sep 2019 22:35:44 +0100 Subject: [PATCH 19/26] Review#3 New Base Class --- homeassistant/components/hive/__init__.py | 51 ++++++++++++------- .../components/hive/binary_sensor.py | 10 ++-- homeassistant/components/hive/climate.py | 28 +++------- homeassistant/components/hive/light.py | 10 ++-- homeassistant/components/hive/sensor.py | 12 +++-- homeassistant/components/hive/switch.py | 10 ++-- homeassistant/components/hive/water_heater.py | 23 +++------ 7 files changed, 72 insertions(+), 72 deletions(-) diff --git a/homeassistant/components/hive/__init__.py b/homeassistant/components/hive/__init__.py index ee394613125c38..176d5cbe5c3972 100644 --- a/homeassistant/components/hive/__init__.py +++ b/homeassistant/components/hive/__init__.py @@ -6,20 +6,23 @@ import voluptuous as vol from homeassistant.const import ( + ATTR_ENTITY_ID, + ATTR_TEMPERATURE, CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME, - ATTR_ENTITY_ID, - ATTR_TEMPERATURE, ) +from homeassistant.core import callback import homeassistant.helpers.config_validation as cv from homeassistant.helpers.discovery import load_platform -from homeassistant.helpers.dispatcher import dispatcher_send +from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send +from homeassistant.helpers.entity import Entity _LOGGER = logging.getLogger(__name__) DOMAIN = "hive" DATA_HIVE = "data_hive" +SERVICES = ["Heating", "HotWater"] SERVICE_BOOST_HOTWATER = "boost_hotwater" SERVICE_BOOST_HEATING = "boost_heating" ATTR_TIME_PERIOD = "time_period" @@ -67,20 +70,6 @@ ) -class HiveSession: - """Initiate Hive Session Class.""" - - entity_lookup = {} - core = None - heating = None - hotwater = None - light = None - sensor = None - switch = None - weather = None - attributes = None - - def setup(hass, config): """Set up the Hive Component.""" @@ -104,7 +93,7 @@ def hotwater_boost(service): # log or raise error _LOGGER.error("Cannot boost entity id entered") return - minutes = service.data.[ATTR_TIME_PERIOD] + minutes = service.data[ATTR_TIME_PERIOD] mode = service.data[ATTR_MODE] if mode == "on": @@ -165,3 +154,29 @@ def wrapper(self, *args, **kwargs): dispatcher_send(self.hass, DOMAIN) return wrapper + + +class HiveSession(Entity): + """Initiate Hive Session Class.""" + + entity_lookup = {} + core = None + heating = None + hotwater = None + light = None + sensor = None + switch = None + weather = None + attributes = None + + async def async_added_to_hass(self): + """When entity is added to Home Assistant.""" + await super().async_added_to_hass() + async_dispatcher_connect(self.hass, DOMAIN, self._update_callback) + if self.device_type in SERVICES: + self.session.entity_lookup[self.entity_id] = self.node_id + + @callback + def _update_callback(self): + """Call update method.""" + self.async_schedule_update_ha_state() diff --git a/homeassistant/components/hive/binary_sensor.py b/homeassistant/components/hive/binary_sensor.py index a61b125d2f0009..566cf0fa275fad 100644 --- a/homeassistant/components/hive/binary_sensor.py +++ b/homeassistant/components/hive/binary_sensor.py @@ -1,7 +1,7 @@ """Support for the Hive binary sensors.""" from homeassistant.components.binary_sensor import BinarySensorDevice -from . import DOMAIN, DATA_HIVE +from . import DOMAIN, DATA_HIVE, HiveSession DEVICETYPE_DEVICE_CLASS = {"motionsensor": "motion", "contactsensor": "opening"} @@ -12,11 +12,13 @@ def setup_platform(hass, config, add_entities, discovery_info=None): return session = hass.data.get(DATA_HIVE) - for device in discovery_info: - add_entities([HiveBinarySensorEntity(session, device)]) + devs = [] + for dev in discovery_info: + devs.append(HiveBinarySensorEntity(session, dev)) + add_entities(devs) -class HiveBinarySensorEntity(BinarySensorDevice): +class HiveBinarySensorEntity(HiveSession, BinarySensorDevice): """Representation of a Hive binary sensor.""" def __init__(self, hivesession, hivedevice): diff --git a/homeassistant/components/hive/climate.py b/homeassistant/components/hive/climate.py index 5e526396dd2dff..545ecb2f6bdf40 100644 --- a/homeassistant/components/hive/climate.py +++ b/homeassistant/components/hive/climate.py @@ -11,9 +11,8 @@ ) from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS -# from homeassistant.helpers.dispatcher import dispatcher_connect -from . import DOMAIN, DATA_HIVE, refresh_system +from . import DOMAIN, DATA_HIVE, HiveSession, refresh_system HIVE_TO_HASS_STATE = { "SCHEDULE": HVAC_MODE_AUTO, @@ -38,11 +37,13 @@ def setup_platform(hass, config, add_entities, discovery_info=None): return session = hass.data.get(DATA_HIVE) - for device in discovery_info: - add_entities([HiveClimateEntity(session, device)]) + devs = [] + for dev in discovery_info: + devs.append(HiveClimateEntity(session, dev)) + add_entities(devs) -class HiveClimateEntity(ClimateDevice): +class HiveClimateEntity(HiveSession, ClimateDevice): """Hive Climate Device.""" def __init__(self, hivesession, hivedevice): @@ -92,7 +93,7 @@ def hvac_modes(self): return SUPPORT_HVAC @property - def hvac_mode(self) -> str: + def hvac_mode(self): """Return hvac operation ie. heat, cool mode. Need to be one of HVAC_MODE_*. @@ -154,24 +155,11 @@ def set_preset_mode(self, preset_mode): """Set new preset mode.""" if preset_mode == PRESET_NONE and self.preset_mode == PRESET_BOOST: self.session.heating.turn_boost_off(self.node_id) - elif preset_mode == PRESET_BOOST: - curtemp = self.session.heating.current_temperature(self.node_id) - curtemp = round(curtemp * 2) / 2 + curtemp = round(self.current_temperature * 2) / 2 temperature = curtemp + 0.5 self.session.heating.turn_boost_on(self.node_id, 30, temperature) - async def async_added_to_hass(self): - """When entity is added to Home Assistant.""" - await super().async_added_to_hass() - self.session.entity_lookup[self.entity_id] = self.node_id - - # dispatcher_connect(self.hass, DOMAIN, self._update_callback) - - # def _update_callback(self): - # """Call update method.""" - # self.schedule_update_ha_state(False) - def update(self): """Update all Node data from Hive.""" self.session.core.update_data(self.node_id) diff --git a/homeassistant/components/hive/light.py b/homeassistant/components/hive/light.py index 344b1eea2eaeeb..24a09510eb2b97 100644 --- a/homeassistant/components/hive/light.py +++ b/homeassistant/components/hive/light.py @@ -10,7 +10,7 @@ ) import homeassistant.util.color as color_util -from . import DOMAIN, DATA_HIVE, refresh_system +from . import DOMAIN, DATA_HIVE, HiveSession, refresh_system def setup_platform(hass, config, add_entities, discovery_info=None): @@ -19,11 +19,13 @@ def setup_platform(hass, config, add_entities, discovery_info=None): return session = hass.data.get(DATA_HIVE) - for device in discovery_info: - add_entities([HiveDeviceLight(session, device)]) + devs = [] + for dev in discovery_info: + devs.append(HiveDeviceLight(session, dev)) + add_entities(devs) -class HiveDeviceLight(Light): +class HiveDeviceLight(HiveSession, Light): """Hive Active Light Device.""" def __init__(self, hivesession, hivedevice): diff --git a/homeassistant/components/hive/sensor.py b/homeassistant/components/hive/sensor.py index 9c751e87247e67..1dc23585bfb217 100644 --- a/homeassistant/components/hive/sensor.py +++ b/homeassistant/components/hive/sensor.py @@ -2,7 +2,7 @@ from homeassistant.const import TEMP_CELSIUS from homeassistant.helpers.entity import Entity -from . import DOMAIN, DATA_HIVE +from . import DOMAIN, DATA_HIVE, HiveSession FRIENDLY_NAMES = { "Hub_OnlineStatus": "Hive Hub Status", @@ -21,12 +21,14 @@ def setup_platform(hass, config, add_entities, discovery_info=None): return session = hass.data.get(DATA_HIVE) - for device in discovery_info: - if device["HA_DeviceType"] in FRIENDLY_NAMES: - add_entities([HiveSensorEntity(session, device)]) + devs = [] + for dev in discovery_info: + if dev["HA_DeviceType"] in FRIENDLY_NAMES: + devs.append(HiveSensorEntity(session, dev)) + add_entities(devs) -class HiveSensorEntity(Entity): +class HiveSensorEntity(HiveSession, Entity): """Hive Sensor Entity.""" def __init__(self, hivesession, hivedevice): diff --git a/homeassistant/components/hive/switch.py b/homeassistant/components/hive/switch.py index 9d6c6d238444c5..23cc8e3a21964b 100644 --- a/homeassistant/components/hive/switch.py +++ b/homeassistant/components/hive/switch.py @@ -1,7 +1,7 @@ """Support for the Hive switches.""" from homeassistant.components.switch import SwitchDevice -from . import DOMAIN, DATA_HIVE, refresh_system +from . import DOMAIN, DATA_HIVE, HiveSession, refresh_system def setup_platform(hass, config, add_entities, discovery_info=None): @@ -10,11 +10,13 @@ def setup_platform(hass, config, add_entities, discovery_info=None): return session = hass.data.get(DATA_HIVE) - for device in discovery_info: - add_entities([HiveDevicePlug(session, device)]) + devs = [] + for dev in discovery_info: + devs.append(HiveDevicePlug(session, dev)) + add_entities(devs) -class HiveDevicePlug(SwitchDevice): +class HiveDevicePlug(HiveSession, SwitchDevice): """Hive Active Plug.""" def __init__(self, hivesession, hivedevice): diff --git a/homeassistant/components/hive/water_heater.py b/homeassistant/components/hive/water_heater.py index ed187331b9d404..dc16cdf27b7d58 100644 --- a/homeassistant/components/hive/water_heater.py +++ b/homeassistant/components/hive/water_heater.py @@ -7,10 +7,7 @@ WaterHeaterDevice, ) from homeassistant.const import TEMP_CELSIUS -from homeassistant.core import callback -from homeassistant.helpers.dispatcher import dispatcher_connect - -from . import DOMAIN, DATA_HIVE, refresh_system +from . import DOMAIN, DATA_HIVE, HiveSession, refresh_system SUPPORT_FLAGS_HEATER = SUPPORT_OPERATION_MODE @@ -25,11 +22,13 @@ def setup_platform(hass, config, add_entities, discovery_info=None): return session = hass.data.get(DATA_HIVE) - for device in discovery_info: - add_entities([HiveWaterHeater(session, device)]) + devs = [] + for dev in discovery_info: + devs.append(HiveWaterHeater(session, dev)) + add_entities(devs) -class HiveWaterHeater(WaterHeaterDevice): +class HiveWaterHeater(HiveSession, WaterHeaterDevice): """Hive Water Heater Device.""" def __init__(self, hivesession, hivedevice): @@ -84,16 +83,6 @@ def set_operation_mode(self, operation_mode): new_mode = HASS_TO_HIVE_STATE[operation_mode] self.session.hotwater.set_mode(self.node_id, new_mode) - async def async_added_to_hass(self): - """When entity is added to Home Assistant.""" - await super().async_added_to_hass() - self.session.entity_lookup[self.entity_id] = self.node_id - dispatcher_connect(self.hass, DOMAIN, self._update_callback) - - @callback - def _update_callback(self) -> None: - self.schedule_update_ha_state() - def update(self): """Update all Node data from Hive.""" self.session.core.update_data(self.node_id) From f2eb36832cc441bc9bdb01a6bd942be210d85ed2 Mon Sep 17 00:00:00 2001 From: KJonline Date: Thu, 26 Sep 2019 19:51:45 +0100 Subject: [PATCH 20/26] Review #5 --- homeassistant/components/hive/__init__.py | 34 ++++++++++++------- .../components/hive/binary_sensor.py | 4 +-- homeassistant/components/hive/climate.py | 4 +-- homeassistant/components/hive/light.py | 13 ++++--- homeassistant/components/hive/sensor.py | 4 +-- homeassistant/components/hive/switch.py | 4 +-- homeassistant/components/hive/water_heater.py | 4 +-- 7 files changed, 38 insertions(+), 29 deletions(-) diff --git a/homeassistant/components/hive/__init__.py b/homeassistant/components/hive/__init__.py index 176d5cbe5c3972..3970916158d70b 100644 --- a/homeassistant/components/hive/__init__.py +++ b/homeassistant/components/hive/__init__.py @@ -70,6 +70,20 @@ ) +class HiveSession: + """Initiate Hive Session Class.""" + + entity_lookup = {} + core = None + heating = None + hotwater = None + light = None + sensor = None + switch = None + weather = None + attributes = None + + def setup(hass, config): """Set up the Hive Component.""" @@ -156,22 +170,18 @@ def wrapper(self, *args, **kwargs): return wrapper -class HiveSession(Entity): - """Initiate Hive Session Class.""" +class HiveEntity(Entity): + """Initiate Hive Base Class.""" - entity_lookup = {} - core = None - heating = None - hotwater = None - light = None - sensor = None - switch = None - weather = None - attributes = None + def __init__(self): + """Initialise the varibale.""" + self.entity_id = None + self.node_id = None + self.device_type = None + self.session = None async def async_added_to_hass(self): """When entity is added to Home Assistant.""" - await super().async_added_to_hass() async_dispatcher_connect(self.hass, DOMAIN, self._update_callback) if self.device_type in SERVICES: self.session.entity_lookup[self.entity_id] = self.node_id diff --git a/homeassistant/components/hive/binary_sensor.py b/homeassistant/components/hive/binary_sensor.py index 566cf0fa275fad..34ce1b22d6792e 100644 --- a/homeassistant/components/hive/binary_sensor.py +++ b/homeassistant/components/hive/binary_sensor.py @@ -1,7 +1,7 @@ """Support for the Hive binary sensors.""" from homeassistant.components.binary_sensor import BinarySensorDevice -from . import DOMAIN, DATA_HIVE, HiveSession +from . import DOMAIN, DATA_HIVE, HiveEntity DEVICETYPE_DEVICE_CLASS = {"motionsensor": "motion", "contactsensor": "opening"} @@ -18,7 +18,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities(devs) -class HiveBinarySensorEntity(HiveSession, BinarySensorDevice): +class HiveBinarySensorEntity(HiveEntity, BinarySensorDevice): """Representation of a Hive binary sensor.""" def __init__(self, hivesession, hivedevice): diff --git a/homeassistant/components/hive/climate.py b/homeassistant/components/hive/climate.py index 545ecb2f6bdf40..34c6b43c02f2fe 100644 --- a/homeassistant/components/hive/climate.py +++ b/homeassistant/components/hive/climate.py @@ -12,7 +12,7 @@ from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS -from . import DOMAIN, DATA_HIVE, HiveSession, refresh_system +from . import DOMAIN, DATA_HIVE, HiveEntity, refresh_system HIVE_TO_HASS_STATE = { "SCHEDULE": HVAC_MODE_AUTO, @@ -43,7 +43,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities(devs) -class HiveClimateEntity(HiveSession, ClimateDevice): +class HiveClimateEntity(HiveEntity, ClimateDevice): """Hive Climate Device.""" def __init__(self, hivesession, hivedevice): diff --git a/homeassistant/components/hive/light.py b/homeassistant/components/hive/light.py index 24a09510eb2b97..50b77b0496289b 100644 --- a/homeassistant/components/hive/light.py +++ b/homeassistant/components/hive/light.py @@ -10,7 +10,7 @@ ) import homeassistant.util.color as color_util -from . import DOMAIN, DATA_HIVE, HiveSession, refresh_system +from . import DOMAIN, DATA_HIVE, HiveEntity, refresh_system def setup_platform(hass, config, add_entities, discovery_info=None): @@ -25,7 +25,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities(devs) -class HiveDeviceLight(HiveSession, Light): +class HiveDeviceLight(HiveEntity, Light): """Hive Active Light Device.""" def __init__(self, hivesession, hivedevice): @@ -149,8 +149,7 @@ def supported_features(self): return supported_features - -def update(self): - """Update all Node data from Hive.""" - self.session.core.update_data(self.node_id) - self.attributes = self.session.attributes.state_attributes(self.node_id) + def update(self): + """Update all Node data from Hive.""" + self.session.core.update_data(self.node_id) + self.attributes = self.session.attributes.state_attributes(self.node_id) diff --git a/homeassistant/components/hive/sensor.py b/homeassistant/components/hive/sensor.py index 1dc23585bfb217..1ee4673f6ca055 100644 --- a/homeassistant/components/hive/sensor.py +++ b/homeassistant/components/hive/sensor.py @@ -2,7 +2,7 @@ from homeassistant.const import TEMP_CELSIUS from homeassistant.helpers.entity import Entity -from . import DOMAIN, DATA_HIVE, HiveSession +from . import DOMAIN, DATA_HIVE, HiveEntity FRIENDLY_NAMES = { "Hub_OnlineStatus": "Hive Hub Status", @@ -28,7 +28,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities(devs) -class HiveSensorEntity(HiveSession, Entity): +class HiveSensorEntity(HiveEntity, Entity): """Hive Sensor Entity.""" def __init__(self, hivesession, hivedevice): diff --git a/homeassistant/components/hive/switch.py b/homeassistant/components/hive/switch.py index 23cc8e3a21964b..0b70071da55096 100644 --- a/homeassistant/components/hive/switch.py +++ b/homeassistant/components/hive/switch.py @@ -1,7 +1,7 @@ """Support for the Hive switches.""" from homeassistant.components.switch import SwitchDevice -from . import DOMAIN, DATA_HIVE, HiveSession, refresh_system +from . import DOMAIN, DATA_HIVE, HiveEntity, refresh_system def setup_platform(hass, config, add_entities, discovery_info=None): @@ -16,7 +16,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities(devs) -class HiveDevicePlug(HiveSession, SwitchDevice): +class HiveDevicePlug(HiveEntity, SwitchDevice): """Hive Active Plug.""" def __init__(self, hivesession, hivedevice): diff --git a/homeassistant/components/hive/water_heater.py b/homeassistant/components/hive/water_heater.py index dc16cdf27b7d58..5f8010fb8be87c 100644 --- a/homeassistant/components/hive/water_heater.py +++ b/homeassistant/components/hive/water_heater.py @@ -7,7 +7,7 @@ WaterHeaterDevice, ) from homeassistant.const import TEMP_CELSIUS -from . import DOMAIN, DATA_HIVE, HiveSession, refresh_system +from . import DOMAIN, DATA_HIVE, HiveEntity, refresh_system SUPPORT_FLAGS_HEATER = SUPPORT_OPERATION_MODE @@ -28,7 +28,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): add_entities(devs) -class HiveWaterHeater(HiveSession, WaterHeaterDevice): +class HiveWaterHeater(HiveEntity, WaterHeaterDevice): """Hive Water Heater Device.""" def __init__(self, hivesession, hivedevice): From 36b851692ed2b5631af228527ac3192c3811161d Mon Sep 17 00:00:00 2001 From: Khole Date: Thu, 26 Sep 2019 20:41:05 +0100 Subject: [PATCH 21/26] Update homeassistant/components/hive/__init__.py Co-Authored-By: Martin Hjelmare --- homeassistant/components/hive/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/hive/__init__.py b/homeassistant/components/hive/__init__.py index 3970916158d70b..f25d90cecf455e 100644 --- a/homeassistant/components/hive/__init__.py +++ b/homeassistant/components/hive/__init__.py @@ -173,7 +173,7 @@ def wrapper(self, *args, **kwargs): class HiveEntity(Entity): """Initiate Hive Base Class.""" - def __init__(self): + def __init__(self, session, hive_device): """Initialise the varibale.""" self.entity_id = None self.node_id = None From c95027a9a0e68272ee134c1e6519893a1b346504 Mon Sep 17 00:00:00 2001 From: Khole Date: Thu, 26 Sep 2019 20:41:21 +0100 Subject: [PATCH 22/26] Update homeassistant/components/hive/__init__.py Co-Authored-By: Martin Hjelmare --- homeassistant/components/hive/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/hive/__init__.py b/homeassistant/components/hive/__init__.py index f25d90cecf455e..46008cddeaf621 100644 --- a/homeassistant/components/hive/__init__.py +++ b/homeassistant/components/hive/__init__.py @@ -174,7 +174,7 @@ class HiveEntity(Entity): """Initiate Hive Base Class.""" def __init__(self, session, hive_device): - """Initialise the varibale.""" + """Initialize the instance.""" self.entity_id = None self.node_id = None self.device_type = None From 5084044306baa37c3b2acd2560dc053cc5efcb1f Mon Sep 17 00:00:00 2001 From: Khole Date: Thu, 26 Sep 2019 20:41:36 +0100 Subject: [PATCH 23/26] Update homeassistant/components/hive/__init__.py Co-Authored-By: Martin Hjelmare --- homeassistant/components/hive/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/homeassistant/components/hive/__init__.py b/homeassistant/components/hive/__init__.py index 46008cddeaf621..cd5cb611a025cd 100644 --- a/homeassistant/components/hive/__init__.py +++ b/homeassistant/components/hive/__init__.py @@ -175,7 +175,6 @@ class HiveEntity(Entity): def __init__(self, session, hive_device): """Initialize the instance.""" - self.entity_id = None self.node_id = None self.device_type = None self.session = None From 73da60c502fc383ba78f4178135f6644b422e716 Mon Sep 17 00:00:00 2001 From: KJonline Date: Thu, 26 Sep 2019 20:57:27 +0100 Subject: [PATCH 24/26] Review 6 --- homeassistant/components/hive/__init__.py | 10 +++++++--- homeassistant/components/hive/binary_sensor.py | 10 ++-------- homeassistant/components/hive/climate.py | 10 ++-------- homeassistant/components/hive/light.py | 11 +++-------- homeassistant/components/hive/sensor.py | 8 ++------ homeassistant/components/hive/switch.py | 9 ++------- homeassistant/components/hive/water_heater.py | 11 +++-------- 7 files changed, 21 insertions(+), 48 deletions(-) diff --git a/homeassistant/components/hive/__init__.py b/homeassistant/components/hive/__init__.py index cd5cb611a025cd..c11eb18accad98 100644 --- a/homeassistant/components/hive/__init__.py +++ b/homeassistant/components/hive/__init__.py @@ -175,9 +175,13 @@ class HiveEntity(Entity): def __init__(self, session, hive_device): """Initialize the instance.""" - self.node_id = None - self.device_type = None - self.session = None + self.node_id = hive_device["Hive_NodeID"] + self.node_name = hive_device["Hive_NodeName"] + self.device_type = hive_device["HA_DeviceType"] + self.node_device_type = hive_device["Hive_DeviceType"] + self.session = session + self.attributes = {} + self._unique_id = f"{self.node_id}-{self.device_type}" async def async_added_to_hass(self): """When entity is added to Home Assistant.""" diff --git a/homeassistant/components/hive/binary_sensor.py b/homeassistant/components/hive/binary_sensor.py index 34ce1b22d6792e..38f300a96467c6 100644 --- a/homeassistant/components/hive/binary_sensor.py +++ b/homeassistant/components/hive/binary_sensor.py @@ -21,15 +21,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None): class HiveBinarySensorEntity(HiveEntity, BinarySensorDevice): """Representation of a Hive binary sensor.""" - def __init__(self, hivesession, hivedevice): + def __init__(self, hive_session, hive_device): """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.attributes = {} - self._unique_id = f"{self.node_id}-{self.device_type}" + super().__init__(hive_session, hive_device) @property def unique_id(self): diff --git a/homeassistant/components/hive/climate.py b/homeassistant/components/hive/climate.py index 34c6b43c02f2fe..415fbb55ec2920 100644 --- a/homeassistant/components/hive/climate.py +++ b/homeassistant/components/hive/climate.py @@ -46,15 +46,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None): class HiveClimateEntity(HiveEntity, ClimateDevice): """Hive Climate Device.""" - def __init__(self, hivesession, hivedevice): + def __init__(self, hive_session, hive_device): """Initialize the Climate device.""" - self.node_id = hivedevice["Hive_NodeID"] - self.node_name = hivedevice["Hive_NodeName"] - self.device_type = hivedevice["HA_DeviceType"] - self.thermostat_node_id = hivedevice["Thermostat_NodeID"] - self.session = hivesession - self.attributes = {} - self._unique_id = f"{self.node_id}-{self.device_type}" + super().__init__(hive_session, hive_device) @property def unique_id(self): diff --git a/homeassistant/components/hive/light.py b/homeassistant/components/hive/light.py index 50b77b0496289b..41fc286d13b0e7 100644 --- a/homeassistant/components/hive/light.py +++ b/homeassistant/components/hive/light.py @@ -28,15 +28,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None): class HiveDeviceLight(HiveEntity, Light): """Hive Active Light Device.""" - def __init__(self, hivesession, hivedevice): + def __init__(self, hive_session, hive_device): """Initialize the Light device.""" - self.node_id = hivedevice["Hive_NodeID"] - self.node_name = hivedevice["Hive_NodeName"] - self.device_type = hivedevice["HA_DeviceType"] - self.light_device_type = hivedevice["Hive_Light_DeviceType"] - self.session = hivesession - self.attributes = {} - self._unique_id = f"{self.node_id}-{self.device_type}" + super().__init__(hive_session, hive_device) + self.light_device_type = hive_device["Hive_Light_DeviceType"] @property def unique_id(self): diff --git a/homeassistant/components/hive/sensor.py b/homeassistant/components/hive/sensor.py index 1ee4673f6ca055..097f1c0a6e9020 100644 --- a/homeassistant/components/hive/sensor.py +++ b/homeassistant/components/hive/sensor.py @@ -31,13 +31,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None): class HiveSensorEntity(HiveEntity, Entity): """Hive Sensor Entity.""" - def __init__(self, hivesession, hivedevice): + def __init__(self, hive_session, hive_device): """Initialize the sensor.""" - self.node_id = hivedevice["Hive_NodeID"] - self.device_type = hivedevice["HA_DeviceType"] - self.node_device_type = hivedevice["Hive_DeviceType"] - self.session = hivesession - self._unique_id = f"{self.node_id}-{self.device_type}" + super().__init__(hive_session, hive_device) @property def unique_id(self): diff --git a/homeassistant/components/hive/switch.py b/homeassistant/components/hive/switch.py index 0b70071da55096..63b7d5bae2fe4c 100644 --- a/homeassistant/components/hive/switch.py +++ b/homeassistant/components/hive/switch.py @@ -19,14 +19,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None): class HiveDevicePlug(HiveEntity, SwitchDevice): """Hive Active Plug.""" - def __init__(self, hivesession, hivedevice): + def __init__(self, hive_session, hive_device): """Initialize the Switch device.""" - self.node_id = hivedevice["Hive_NodeID"] - self.node_name = hivedevice["Hive_NodeName"] - self.device_type = hivedevice["HA_DeviceType"] - self.session = hivesession - self.attributes = {} - self._unique_id = f"{self.node_id}-{self.device_type}" + super().__init__(hive_session, hive_device) @property def unique_id(self): diff --git a/homeassistant/components/hive/water_heater.py b/homeassistant/components/hive/water_heater.py index 5f8010fb8be87c..e0e54aacbf4ccf 100644 --- a/homeassistant/components/hive/water_heater.py +++ b/homeassistant/components/hive/water_heater.py @@ -31,14 +31,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None): class HiveWaterHeater(HiveEntity, WaterHeaterDevice): """Hive Water Heater Device.""" - def __init__(self, hivesession, hivedevice): + def __init__(self, hive_session, hive_device): """Initialize the Water Heater device.""" - self.node_id = hivedevice["Hive_NodeID"] - self.node_name = hivedevice["Hive_NodeName"] - self.device_type = hivedevice["HA_DeviceType"] - self.session = hivesession - self._unique_id = f"{self.node_id}-{self.device_type}" - self._unit_of_measurement = TEMP_CELSIUS + super().__init__(hive_session, hive_device) @property def unique_id(self): @@ -65,7 +60,7 @@ def name(self): @property def temperature_unit(self): """Return the unit of measurement.""" - return self._unit_of_measurement + return TEMP_CELSIUS @property def current_operation(self): From 727604513cea4b6b586c7770a9f68dddc11d8b46 Mon Sep 17 00:00:00 2001 From: KJonline Date: Thu, 26 Sep 2019 21:16:39 +0100 Subject: [PATCH 25/26] Review 7 --- homeassistant/components/hive/climate.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/hive/climate.py b/homeassistant/components/hive/climate.py index 415fbb55ec2920..1fb77ce6cb9731 100644 --- a/homeassistant/components/hive/climate.py +++ b/homeassistant/components/hive/climate.py @@ -49,6 +49,7 @@ class HiveClimateEntity(HiveEntity, ClimateDevice): def __init__(self, hive_session, hive_device): """Initialize the Climate device.""" super().__init__(hive_session, hive_device) + self.thermostat_node_id = hive_device["Thermostat_NodeID"] @property def unique_id(self): From 1ed828e8b7f3c33e4d7d7f6c42f060895506b581 Mon Sep 17 00:00:00 2001 From: Khole Date: Fri, 27 Sep 2019 18:47:24 +0100 Subject: [PATCH 26/26] Removed Child classes to inhertit from the parent --- homeassistant/components/hive/binary_sensor.py | 4 ---- homeassistant/components/hive/sensor.py | 4 ---- homeassistant/components/hive/switch.py | 4 ---- homeassistant/components/hive/water_heater.py | 4 ---- 4 files changed, 16 deletions(-) diff --git a/homeassistant/components/hive/binary_sensor.py b/homeassistant/components/hive/binary_sensor.py index 38f300a96467c6..ce7e53b77a5263 100644 --- a/homeassistant/components/hive/binary_sensor.py +++ b/homeassistant/components/hive/binary_sensor.py @@ -21,10 +21,6 @@ def setup_platform(hass, config, add_entities, discovery_info=None): class HiveBinarySensorEntity(HiveEntity, BinarySensorDevice): """Representation of a Hive binary sensor.""" - def __init__(self, hive_session, hive_device): - """Initialize the hive sensor.""" - super().__init__(hive_session, hive_device) - @property def unique_id(self): """Return unique ID of entity.""" diff --git a/homeassistant/components/hive/sensor.py b/homeassistant/components/hive/sensor.py index 097f1c0a6e9020..ccd635015de320 100644 --- a/homeassistant/components/hive/sensor.py +++ b/homeassistant/components/hive/sensor.py @@ -31,10 +31,6 @@ def setup_platform(hass, config, add_entities, discovery_info=None): class HiveSensorEntity(HiveEntity, Entity): """Hive Sensor Entity.""" - def __init__(self, hive_session, hive_device): - """Initialize the sensor.""" - super().__init__(hive_session, hive_device) - @property def unique_id(self): """Return unique ID of entity.""" diff --git a/homeassistant/components/hive/switch.py b/homeassistant/components/hive/switch.py index 63b7d5bae2fe4c..1447f5483a4a0e 100644 --- a/homeassistant/components/hive/switch.py +++ b/homeassistant/components/hive/switch.py @@ -19,10 +19,6 @@ def setup_platform(hass, config, add_entities, discovery_info=None): class HiveDevicePlug(HiveEntity, SwitchDevice): """Hive Active Plug.""" - def __init__(self, hive_session, hive_device): - """Initialize the Switch device.""" - super().__init__(hive_session, hive_device) - @property def unique_id(self): """Return unique ID of entity.""" diff --git a/homeassistant/components/hive/water_heater.py b/homeassistant/components/hive/water_heater.py index e0e54aacbf4ccf..c60a9ec01d1fcf 100644 --- a/homeassistant/components/hive/water_heater.py +++ b/homeassistant/components/hive/water_heater.py @@ -31,10 +31,6 @@ def setup_platform(hass, config, add_entities, discovery_info=None): class HiveWaterHeater(HiveEntity, WaterHeaterDevice): """Hive Water Heater Device.""" - def __init__(self, hive_session, hive_device): - """Initialize the Water Heater device.""" - super().__init__(hive_session, hive_device) - @property def unique_id(self): """Return unique ID of entity."""