Skip to content

Commit 2bb54ad

Browse files
authored
Merge pull request #92 from plugwise/usb_energy
Add energy support for Stick
2 parents f3f57ce + afeecb4 commit 2bb54ad

File tree

7 files changed

+478
-116
lines changed

7 files changed

+478
-116
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 0.12.0 - Energy support and bugfixes
4+
5+
- Stick: Add new properties `energy_consumption_today` counter and `energy_consumption_today_last_reset` timestamp. These properties can be used to properly measure the used energy. Very useful for the 'Energy' capabilities introduced in Home Assistant 2021.8
6+
- Stick: Synchronize clock of all plugwise devices once a day
7+
- Stick: Reduced local clock drift from 30 to 5 seconds
8+
- Stick: Optimized retrieval and handling of energy history
9+
310
## 0.11.2 - Fix new and remaining pylint warnings
411

512
## 0.11.1 - Code improvements

plugwise/constants.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157

158158
# Max seconds the internal clock of plugwise nodes
159159
# are allowed to drift in seconds
160-
MAX_TIME_DRIFT = 30
160+
MAX_TIME_DRIFT = 5
161161

162162
# Default sleep time in seconds for watchdog daemon
163163
WATCHDOG_DEAMON = 60
@@ -251,6 +251,12 @@
251251
"state": "available",
252252
"unit": "state",
253253
}
254+
FEATURE_ENERGY_CONSUMPTION_TODAY = {
255+
"id": "energy_consumption_today",
256+
"name": "Energy consumption today",
257+
"state": "Energy_consumption_today",
258+
"unit": ENERGY_KILO_WATT_HOUR,
259+
}
254260
FEATURE_HUMIDITY = {
255261
"id": "humidity",
256262
"name": "Humidity",

plugwise/messages/requests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,11 @@ def __init__(self, group_mac, switch_state: bool):
339339
self.args.append(Int(val, length=2))
340340

341341

342-
class CirclePowerBufferRequest(NodeRequest):
342+
class CircleEnergyCountersRequest(NodeRequest):
343343
"""
344-
Request power usage storaged a given memory address
344+
Request energy usage counters storaged a given memory address
345345
346-
Response message: CirclePowerBufferResponse
346+
Response message: CircleEnergyCountersResponse
347347
"""
348348

349349
ID = b"0048"

plugwise/messages/responses.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,12 @@ def __init__(self):
406406
self.params += [self.time, self.day_of_week, self.unknown, self.unknown2]
407407

408408

409-
class CirclePowerBufferResponse(NodeResponse):
409+
class CircleEnergyCountersResponse(NodeResponse):
410410
"""
411-
returns information about historical power usage
412-
each response contains 4 log buffers and each log buffer contains data for 1 hour
411+
Returns historical energy usage of requested memory address
412+
Each response contains 4 energy counters at specified 1 hour timestamp
413413
414-
Response to: CirclePowerBufferRequest
414+
Response to: CircleEnergyCountersRequest
415415
"""
416416

417417
ID = b"0049"
@@ -576,7 +576,7 @@ def __init__(self):
576576
b"0027": CircleCalibrationResponse(),
577577
b"003A": CirclePlusRealTimeClockResponse(),
578578
b"003F": CircleClockResponse(),
579-
b"0049": CirclePowerBufferResponse(),
579+
b"0049": CircleEnergyCountersResponse(),
580580
b"0060": NodeFeaturesResponse(),
581581
b"0100": NodeAckResponse(),
582582
b"0105": SenseReportResponse(),

plugwise/nodes/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class PlugwiseNode:
3030
def __init__(self, mac, address, message_sender):
3131
mac = mac.upper()
3232
if not validate_mac(mac):
33-
_LOGGER.debug(
33+
_LOGGER.warning(
3434
"MAC address is in unexpected format: %s",
3535
str(mac),
3636
)
@@ -51,7 +51,6 @@ def __init__(self, mac, address, message_sender):
5151
self._firmware_version = None
5252
self._relay_state = False
5353
self._last_log_address = None
54-
self.last_info_message = None
5554
self._device_features = None
5655

5756
@property
@@ -266,7 +265,11 @@ def _process_ping_response(self, message):
266265

267266
def _process_info_response(self, message):
268267
"""Process info response message."""
269-
_LOGGER.debug("Response info message for node %s", self.mac)
268+
_LOGGER.debug(
269+
"Response info message for node %s, last log address %s",
270+
self.mac,
271+
str(message.last_logaddr.value),
272+
)
270273
if message.relay_state.serialize() == b"01":
271274
if not self._relay_state:
272275
self._relay_state = True
@@ -278,7 +281,6 @@ def _process_info_response(self, message):
278281
self._hardware_version = message.hw_ver.value.decode(UTF8_DECODE)
279282
self._firmware_version = message.fw_ver.value
280283
self._node_type = message.node_type.value
281-
self.last_info_message = message.timestamp
282284
if self._last_log_address != message.last_logaddr.value:
283285
self._last_log_address = message.last_logaddr.value
284286
_LOGGER.debug("Node type = %s", self.hardware_model)

0 commit comments

Comments
 (0)