Skip to content

Commit e53b1d7

Browse files
authored
Merge pull request #4 from plugwise/demand
Demand
2 parents fcb3037 + 8d35f6d commit e53b1d7

File tree

6 files changed

+91
-87
lines changed

6 files changed

+91
-87
lines changed

custom_components/plugwise-beta/__init__.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,8 @@
44
import logging
55
from datetime import timedelta
66
from typing import Optional
7-
87
import voluptuous as vol
98

10-
from homeassistant.components.climate.const import (
11-
HVAC_MODE_AUTO,
12-
HVAC_MODE_HEAT,
13-
HVAC_MODE_HEAT_COOL,
14-
SUPPORT_PRESET_MODE,
15-
SUPPORT_TARGET_TEMPERATURE,
16-
)
179
from homeassistant.config_entries import ConfigEntry
1810
from homeassistant.core import HomeAssistant, callback
1911
from homeassistant.helpers import device_registry as dr
@@ -25,12 +17,6 @@
2517

2618
CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({})}, extra=vol.ALLOW_EXTRA)
2719

28-
# HVAC modes
29-
HVAC_MODES_1 = [HVAC_MODE_HEAT, HVAC_MODE_AUTO]
30-
HVAC_MODES_2 = [HVAC_MODE_HEAT_COOL, HVAC_MODE_AUTO]
31-
32-
SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
33-
3420
_LOGGER = logging.getLogger(__name__)
3521

3622
PLATFORMS = ["climate", "sensor", "switch", "water_heater"]
@@ -40,7 +26,6 @@ async def async_setup(hass: HomeAssistant, config: dict):
4026
"""Set up the Plugwise platform."""
4127
return True
4228

43-
4429
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
4530
"""Set up Plugwise Smiles from a config entry."""
4631

@@ -80,7 +65,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
8065
)
8166
_LOGGER.debug("Plugwise device registry %s", result)
8267

83-
for component in PLATFORMS: # api._platforms
68+
for component in PLATFORMS:
8469
hass.async_create_task(
8570
hass.config_entries.async_forward_entry_setup(entry, component)
8671
)
@@ -94,7 +79,6 @@ async def async_refresh_all(_):
9479

9580
return True
9681

97-
9882
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
9983
"""Unload a config entry."""
10084
unload_ok = all(

custom_components/plugwise-beta/climate.py

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Plugwise Climate component for Home Assistant."""
22

33
import logging
4-
from datetime import timedelta
54
from typing import Dict
65

76
from homeassistant.components.climate import ClimateDevice
@@ -19,15 +18,21 @@
1918
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
2019
from homeassistant.core import callback
2120

22-
from . import HVAC_MODES_1, HVAC_MODES_2
23-
from .const import DOMAIN, THERMOSTAT_ICON
21+
from .const import (
22+
DOMAIN,
23+
THERMOSTAT_ICON,
24+
DEFAULT_MIN_TEMP,
25+
DEFAULT_MAX_TEMP,
26+
)
27+
28+
# HVAC modes
29+
HVAC_MODES_1 = [HVAC_MODE_HEAT, HVAC_MODE_AUTO]
30+
HVAC_MODES_2 = [HVAC_MODE_HEAT_COOL, HVAC_MODE_AUTO]
2431

2532
SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
2633

2734
_LOGGER = logging.getLogger(__name__)
2835

29-
SCAN_INTERVAL = timedelta(seconds=30)
30-
3136

3237
async def async_setup_entry(hass, config_entry, async_add_entities):
3338
"""Set up the Smile Thermostats from a config entry."""
@@ -43,7 +48,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
4348

4449
_LOGGER.debug("Plugwise climate Dev %s", device["name"])
4550
thermostat = PwThermostat(
46-
api, updater, device["name"], dev_id, device["location"], 4, 30
51+
api,
52+
updater,
53+
device["name"],
54+
dev_id, device["location"],
55+
DEFAULT_MIN_TEMP,
56+
DEFAULT_MAX_TEMP,
4757
)
4858

4959
if not thermostat:
@@ -82,7 +92,6 @@ def __init__(self, api, updater, name, dev_id, loc_id, min_temp, max_temp):
8292
self._schema_status = None
8393
self._temperature = None
8494
self._thermostat = None
85-
self._boiler_temp = None
8695
self._water_pressure = None
8796
self._schedule_temp = None
8897
self._hvac_mode = None
@@ -106,20 +115,23 @@ def _update_callback(self):
106115
"""Call update method."""
107116
self.update()
108117
self.async_write_ha_state()
109-
# self.async_schedule_update_ha_state(True)
110118

111119
@property
112120
def hvac_action(self):
113121
"""Return the current action."""
114-
if (
115-
self._central_heating_state
116-
or self._boiler_status
117-
or self._domestic_hot_water_state
118-
):
119-
return CURRENT_HVAC_HEAT
120-
if self._cooling_status:
121-
return CURRENT_HVAC_COOL
122+
if (self._central_heating_state is not None or self._boiler_status is not None) and self._cooling_status is None:
123+
if self._thermostat > self._temperature:
124+
return CURRENT_HVAC_HEAT
122125
return CURRENT_HVAC_IDLE
126+
#if (
127+
# self._central_heating_state
128+
# or self._boiler_status
129+
# or self._domestic_hot_water_state
130+
#):
131+
# return CURRENT_HVAC_HEAT
132+
#if self._cooling_status:
133+
# return CURRENT_HVAC_COOL
134+
#return CURRENT_HVAC_IDLE
123135

124136
@property
125137
def name(self):
@@ -280,8 +292,6 @@ def update(self):
280292
_LOGGER.error("Received no heater_central_data for device %s.", self._name)
281293
else:
282294
_LOGGER.debug("Heater_central_data collected from Plugwise API")
283-
if "boiler_temp" in heater_central_data:
284-
self._boiler_temp = heater_central_data["boiler_temp"]
285295
if "boiler_state" in heater_central_data:
286296
if heater_central_data["boiler_state"] is not None:
287297
self._boiler_status = heater_central_data["boiler_state"] == "on"
@@ -293,11 +303,6 @@ def update(self):
293303
if "cooling_state" in heater_central_data:
294304
if heater_central_data["cooling_state"] is not None:
295305
self._cooling_status = heater_central_data["cooling_state"] == "on"
296-
if "domestic_hot_water_state" in heater_central_data:
297-
if heater_central_data["domestic_hot_water_state"] is not None:
298-
self._domestic_hot_water_state = (
299-
heater_central_data["domestic_hot_water_state"] == "on"
300-
)
301306

302307
if self._schema_status:
303308
self._hvac_mode = HVAC_MODE_AUTO

custom_components/plugwise-beta/const.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@
2424
CONF_GAS = "gas"
2525

2626
ATTR_ILLUMINANCE = "illuminance"
27+
CURRENT_HVAC_DHW = "hot_water"
2728

2829
# Icons
2930
SWITCH_ICON = "mdi:electric-switch"
3031
THERMOSTAT_ICON = "mdi:thermometer"
3132
WATER_HEATER_ICON = "mdi:water-pump"
33+
FLAME_ICON = "mdi:fire"
34+
IDLE_ICON = "mdi:close-circle-outline"
3235
GAS_ICON = "mdi:fire"
3336
POWER_ICON = "mdi:flash"
3437
POWER_FAILURE_ICON = "mdi:flash-off"

custom_components/plugwise-beta/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"domain": "plugwise-beta",
33
"name": "Plugwise Beta for Home Assistant",
44
"documentation": "",
5-
"requirements": ["Plugwise_Smile==0.0.40"],
5+
"requirements": ["Plugwise_Smile==0.0.42"],
66
"dependencies": [],
77
"codeowners": ["@CoMPaTech","@bouwew"],
88
"config_flow": true

custom_components/plugwise-beta/sensor.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Plugwise Sensor component for Home Assistant."""
22

33
import logging
4-
from datetime import timedelta
54
from typing import Dict
65

76
from homeassistant.const import (
@@ -18,9 +17,6 @@
1817

1918
from .const import DEVICE_CLASS_GAS, DOMAIN
2019

21-
DEFAULT_NAME = "Plugwise async sensor"
22-
DEFAULT_ICON = "mdi:thermometer"
23-
2420
_LOGGER = logging.getLogger(__name__)
2521

2622
ATTR_TEMPERATURE = [
@@ -68,7 +64,6 @@
6864
"mdi:flash",
6965
],
7066
"outdoor_temperature": ATTR_TEMPERATURE,
71-
"central_heater_water_pressure": ATTR_PRESSURE,
7267
"illuminance": ATTR_ILLUMINANCE,
7368
"boiler_temperature": ATTR_TEMPERATURE,
7469
"electricity_consumed_off_peak_point": [
@@ -145,28 +140,6 @@
145140
],
146141
}
147142

148-
# TODO:
149-
# 'relay',
150-
# 'valve_position',
151-
# 'boiler_state',
152-
# 'central_heating_state',
153-
# 'cooling_state',
154-
# 'dhw_state',
155-
156-
# TODO:
157-
# 'electricity_consumption_tariff_structure',
158-
# 'electricity_consumption_peak_tariff',
159-
# 'electricity_consumption_off_peak_tariff',
160-
# 'electricity_production_peak_tariff',
161-
# 'electricity_production_off_peak_tariff',
162-
# 'electricity_consumption_single_tariff',
163-
# 'electricity_production_single_tariff',
164-
# 'gas_consumption_tariff',
165-
166-
# Scan interval for updating sensor values
167-
# Smile communication is set using configuration directives
168-
SCAN_INTERVAL = timedelta(seconds=30)
169-
170143

171144
async def async_setup_entry(hass, config_entry, async_add_entities):
172145
"""Set up the Smile sensors from a config entry."""
@@ -186,8 +159,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
186159
for sensor, sensor_type in SENSOR_MAP.items():
187160
if sensor in data:
188161
if data[sensor] is not None:
189-
# _LOGGER.info('Plugwise sensor is %s for %s (%s)',sensor,dev_id,device)
190-
# _LOGGER.info('Plugwise sensor data %s for %s',data,dev_id)
191162
if "power" in device["types"]:
192163
if (
193164
"off" in sensor
@@ -396,7 +367,6 @@ def update(self):
396367
if self._sensor in data:
397368
if data[self._sensor] is not None:
398369
measurement = data[self._sensor]
399-
# _LOGGER.debug("Sensor value: %s", measurement)
400370
if self._unit_of_measurement == "kWh":
401371
measurement = int(measurement / 1000)
402372
self._state = measurement

custom_components/plugwise-beta/water_heater.py

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,22 @@
33
import logging
44
from typing import Dict
55

6-
from homeassistant.const import STATE_OFF, STATE_ON
76
from homeassistant.core import callback
87
from homeassistant.helpers.entity import Entity
98

10-
from .const import DOMAIN, WATER_HEATER_ICON
9+
from homeassistant.components.climate.const import (
10+
CURRENT_HVAC_COOL,
11+
CURRENT_HVAC_HEAT,
12+
CURRENT_HVAC_IDLE,
13+
)
14+
15+
from .const import (
16+
CURRENT_HVAC_DHW,
17+
DOMAIN,
18+
FLAME_ICON,
19+
IDLE_ICON,
20+
WATER_HEATER_ICON,
21+
)
1122

1223
_LOGGER = logging.getLogger(__name__)
1324

@@ -22,12 +33,11 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
2233
for dev_id, device in all_devices.items():
2334
if device["class"] == "heater_central":
2435
data = api.get_device_data(dev_id)
25-
if "domestic_hot_water_state" in data:
26-
if data["domestic_hot_water_state"] is not None:
27-
_LOGGER.debug("Plugwise water_heater Dev %s", device["name"])
28-
water_heater = PwWaterHeater(api, updater, device["name"], dev_id)
29-
devices.append(water_heater)
30-
_LOGGER.info("Added water_heater.%s", "{}".format(device["name"]))
36+
if "boiler_temperature" in data:
37+
_LOGGER.debug("Plugwise water_heater Dev %s", device["name"])
38+
water_heater = PwWaterHeater(api, updater, device["name"], dev_id)
39+
devices.append(water_heater)
40+
_LOGGER.info("Added water_heater.%s", "{}".format(device["name"]))
3141

3242
async_add_entities(devices, True)
3343

@@ -41,7 +51,11 @@ def __init__(self, api, updater, name, dev_id):
4151
self._updater = updater
4252
self._name = name
4353
self._dev_id = dev_id
44-
self._domestic_hot_water_state = None
54+
self._boiler_state = False
55+
self._boiler_temp = None
56+
self._central_heating_state = False
57+
self._central_heater_water_pressure = None
58+
self._domestic_hot_water_state = False
4559
self._unique_id = f"{dev_id}-water_heater"
4660

4761
@property
@@ -80,15 +94,32 @@ def device_info(self) -> Dict[str, any]:
8094

8195
@property
8296
def state(self):
83-
"""Return the state of the sensor."""
84-
if self._domestic_hot_water_state:
85-
return STATE_ON
86-
return STATE_OFF
97+
"""Return the state of the water_heater."""
98+
if self._central_heating_state or self._boiler_state:
99+
return CURRENT_HVAC_HEAT
100+
elif self._domestic_hot_water_state:
101+
return CURRENT_HVAC_DHW
102+
else:
103+
return CURRENT_HVAC_IDLE
104+
105+
@property
106+
def device_state_attributes(self):
107+
"""Return the optional device state attributes."""
108+
attributes = {}
109+
attributes["current_operation"] = self.state
110+
attributes["current_temperature"] = self._boiler_temp
111+
attributes["water_pressure"] = self._central_heater_water_pressure
112+
return attributes
87113

88114
@property
89115
def icon(self):
90116
"""Return the icon to use in the frontend."""
91-
return WATER_HEATER_ICON
117+
if self._central_heating_state or self._boiler_state:
118+
return FLAME_ICON
119+
elif self._domestic_hot_water_state:
120+
return WATER_HEATER_ICON
121+
else:
122+
return IDLE_ICON
92123

93124
@property
94125
def should_poll(self):
@@ -97,13 +128,24 @@ def should_poll(self):
97128

98129
def update(self):
99130
"""Update the entity."""
100-
101-
_LOGGER.debug("Update sensor called")
131+
_LOGGER.debug("Update water_heater called")
102132
data = self._api.get_device_data(self._dev_id)
103133

104134
if data is None:
105135
_LOGGER.error("Received no data for device %s.", self._name)
106136
else:
137+
if "boiler_temperature" in data:
138+
self._boiler_temp = data["boiler_temperature"]
139+
if "central_heater_water_pressure" in data:
140+
self._central_heater_water_pressure = data["central_heater_water_pressure"]
141+
if "boiler_state" in data:
142+
if data["boiler_state"] is not None:
143+
self._boiler_state = (data["boiler_state"] == "on")
144+
if "central_heating_state" in data:
145+
if data["central_heating_state"] is not None:
146+
self._central_heating_state = (
147+
data["central_heating_state"] == "on"
148+
)
107149
if "domestic_hot_water_state" in data:
108150
self._domestic_hot_water_state = (
109151
data["domestic_hot_water_state"] == "on"

0 commit comments

Comments
 (0)