Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
a3c8a69
Make available a property
brefra Dec 23, 2020
7ffa6f0
Make mac a property
brefra Dec 23, 2020
d798c52
Make relay_state a property
brefra Dec 23, 2020
cab7846
Make hardware_model a property
brefra Dec 23, 2020
a3d3efc
Make name a property
brefra Dec 23, 2020
914f864
Make hardware_version a property
brefra Dec 23, 2020
7a8afbd
Make firmware_version a property
brefra Dec 23, 2020
045a7ea
Make last_update a property
brefra Dec 23, 2020
bb6d59e
Make ping a property
brefra Dec 23, 2020
2111433
Make rssi_in a property
brefra Dec 23, 2020
702fa3c
Make rssi_out a property
brefra Dec 23, 2020
9d277df
Make switches a property
brefra Dec 23, 2020
9aaa217
Make sensors a property
brefra Dec 23, 2020
339b3b7
Rename ping function into do_ping
brefra Dec 23, 2020
c8782ac
Make categories a property
brefra Dec 23, 2020
3e5a7ce
Make battery_powered a property
brefra Dec 23, 2020
e79a823
Make measures_power a property
brefra Dec 23, 2020
20e2a0f
Rename do_ping into _request_ping to be consistent
brefra Dec 23, 2020
85f9546
Make current_power_usage a property
brefra Dec 23, 2020
0dc6418
Make current_power_usage_8_sec a property
brefra Dec 23, 2020
24a5fb6
Make power_consumption_current_hour a property
brefra Dec 23, 2020
39fef65
Make power_production_current_hour a property
brefra Dec 23, 2020
9dd5db0
Make power_consumption_previous_hour a property
brefra Dec 23, 2020
5db9db3
Make power_consumption_today a property
brefra Dec 23, 2020
d424938
Make power_consumption_yesterday a property
brefra Dec 23, 2020
fadcd11
Replace all self.get_mac() with self.mac
brefra Dec 23, 2020
4b046c8
Make motion a property
brefra Dec 23, 2020
e6cb3d8
Correct missed constants & hardware_model
brefra Dec 23, 2020
a8bf896
Make mac a property at stick class
brefra Dec 23, 2020
49b0d36
Make joined_nodes a property
brefra Dec 23, 2020
e0b3fe0
Make discovered_nodes a property
brefra Dec 23, 2020
8c278e8
Move functions to deprecate to bottom of file
brefra Dec 23, 2020
3bf8883
Make temperature a property
brefra Dec 23, 2020
96a3994
Make humidity a property
brefra Dec 23, 2020
f79cb9e
Make network_state a property
brefra Dec 23, 2020
2eb64a3
Make network_id a property
brefra Dec 23, 2020
b0e510a
Correct comments
brefra Dec 23, 2020
f53cbfd
Improve relay_state changes
brefra Dec 24, 2020
86933ef
Log resend of messages at info level
brefra Dec 24, 2020
e1fa5eb
Make parameter of _request_ping well defined
brefra Dec 26, 2020
56beffc
Rename request_info to _request_info to be consistant
brefra Dec 27, 2020
ac761ec
Add port property to stick.py
brefra Dec 29, 2020
5220b20
Rename update_power_usage to _request_power_update to be consistent
brefra Dec 29, 2020
d25c557
Reorder properties stick.py
brefra Dec 29, 2020
8fe1069
Reorder properties sense.py
brefra Dec 29, 2020
3bcc37d
Reorder properties circle.py
brefra Dec 29, 2020
aad35a7
Reorder properties nodes
brefra Dec 29, 2020
6661144
Correct humidity and temperature state in constants.py
brefra Dec 29, 2020
7103af2
Update changelog and bump to 0.8.7
brefra Dec 29, 2020
970098b
Refactor exposing features of nodes
brefra Dec 29, 2020
7ed026e
Make switch a property
brefra Dec 29, 2020
c0ea108
Reorder changelog
brefra Dec 29, 2020
09dfb44
Correct imports
brefra Dec 30, 2020
4a8dedc
Remove accidentally added line
brefra Dec 30, 2020
4348454
Change feature value to string
brefra Dec 30, 2020
c6899e1
Bump version to 0.9.0.a0
brefra Dec 30, 2020
05c86e3
Change update timer on number of active nodes
brefra Dec 31, 2020
3a1a65e
Implement priority queue for sending messages
brefra Dec 31, 2020
d0bedbd
Remove unused import circle.py
brefra Dec 31, 2020
d487f07
Update changelog
brefra Dec 31, 2020
0f6eb2a
Bump version to 0.9.0.a1
brefra Dec 31, 2020
c4f0171
Fix typo in comment
brefra Dec 31, 2020
54c9a2b
Reorder imports controller.py
brefra Dec 31, 2020
6d30990
Simplify datetime deserialize at util.py
brefra Jan 2, 2021
ba3e76c
Add warning log when node doesn't exists
brefra Jan 2, 2021
c76e4ce
Simplify discover_node in stick.py
brefra Jan 2, 2021
bc8637d
Make devices a property
brefra Jan 2, 2021
96f612d
Drop discovered_nodes property
brefra Jan 2, 2021
6015873
Some code cleanup and formatting
brefra Jan 3, 2021
99fd489
Bump version to 0.9.0.a2
brefra Jan 3, 2021
0a877ce
Correct priority const
brefra Jan 19, 2021
1a4f4a0
Correct some comments
brefra Jan 19, 2021
95bf5bd
Bump version to 0.9.0.a3
brefra Jan 19, 2021
fc1a5ee
Correct typo in docstring
brefra Jan 19, 2021
4373835
Revert "Remove aiohttp-workaround"
bouwew Dec 12, 2020
1212227
Improve code
bouwew Jan 22, 2021
b9c8ead
Apply markdown formatting to CHANGELOG.md
brefra Jan 23, 2021
6e9e962
Bump versio to 0.9.0
brefra Jan 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,50 @@
# Changelog

## 0.9.0 - API change for stick

- Improvement: Debounce relay state
- Improvement: Prioritize request so requests like switching a relay get send out before power measurement requests.
- Improvement: Dynamically change the refresh interval based on the actual discovered nodes with power measurement capabilities
- Added: New property attributes for USB-stick.
The old methods are still available but will give a deprecate warning
- Stick
- `devices` (dict) - All discovered and supported plugwise devices with the MAC address as their key
- `joined_nodes` (integer) - Total number of registered nodes at Plugwise Circle+
- `mac` (string) - The MAC address of the USB-Stick
- `network_state` (boolean) - The state (on-line/off-line) of the Plugwise network.
- `network_id` (integer) - The ID of the Plugwise network.
- `port` (string) - The port connection string
- All plugwise devices
- `available` (boolean) - The current network availability state of the device
- `battery_powered` (boolean) - Indicates if device is battery powered
- `features` (tuple) - List of supported attribute IDs
- `firmware_version` (string) - Firmware version device is running
- `hardware_model` (string) - Hardware model name
- `hardware_version` (string) - Hardware version of device
- `last_update` (datetime) - Date/time stamp of last received update from device
- `mac` (string) - MAC address of device
- `measures_power` (boolean) - Indicates if device supports power measurement
- `name` (string) - Name of device based om hardware model and MAC address
- `ping` (integer) - Network roundtrip time in milliseconds
- `rssi_in` (integer) - Inbound RSSI level in DBm
- `rssi_out` (integer) - Outbound RSSI level based on the received inbound RSSI level of the neighbor node in DBm
- Scan devices
- `motion` (boolean) - Current detection state of motion.
- Sense devices
- `humidity` (integer) - Last reported humidity value.
- `temperature` (integer) - Last reported temperature value.
- Circle/Circle+/Stealth devices
- `current_power_usage` (float) - Current power usage (Watts) during the last second
- `current_power_usage_8_sec` (float) - Current power usage (Watts) during the last 8 seconds
- `power_consumption_current_hour` (float) - Total power consumption (kWh) this running hour
- `power_consumption_previous_hour` (float) - Total power consumption (kWh) during the previous hour
- `power_consumption_today` (float) - Total power consumption (kWh) of today
- `power_consumption_yesterday` (float) - Total power consumption (kWh) during yesterday
- `power_production_current_hour` (float) - Total power production (kWh) this hour
- `relay_state` (boolean) - State of the output power relay. Setting this property will operate the relay
- Switch devices
- `switch` (boolean) - Last reported state of switch

## 0.8.6 - Code quality improvements for stick

- Bug-fix: Power history was not reported (0 value) during last week of the month
Expand All @@ -17,9 +62,10 @@
- Improvement: Resolves all flake8 comments

## 0.8.5 - Fix sensor scaling
- Fix for via HA Core issue #44349
- Fix other value scaling bugs
- Remove aiohttp-workaround - issue solved in aiohttp 3.7.1

- Fix for via HA Core issue #44349
- Fix other value scaling bugs
- Remove aiohttp-workaround - issue solved in aiohttp 3.7.1

(## 0.8.4 - Not released: Fix "Gas Consumed Interval stays 0" )

Expand Down
2 changes: 1 addition & 1 deletion plugwise/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Plugwise module."""

__version__ = "0.8.6"
__version__ = "0.9.0"

from plugwise.smile import Smile
from plugwise.stick import stick
93 changes: 45 additions & 48 deletions plugwise/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@
# Default sleep between sending messages
SLEEP_TIME = 150 / 1000

# Message priority levels
PRIORITY_HIGH = 1
PRIORITY_LOW = 3
PRIORITY_MEDIUM = 2

# Max seconds the internal clock of plugwise nodes
# are allowed to drift in seconds
MAX_TIME_DRIFT = 30
Expand Down Expand Up @@ -220,120 +225,112 @@
CB_NEW_NODE = "NEW_NODE"
CB_JOIN_REQUEST = "JOIN_REQUEST"

# Sensors
SENSOR_AVAILABLE = {
# Stick device features
FEATURE_AVAILABLE = {
"id": "available",
"name": "Available",
"state": "get_available",
"state": "available",
"unit": "state",
}
SENSOR_HUMIDITY = {
FEATURE_HUMIDITY = {
"id": "humidity",
"name": "Humidity",
"state": "get_humidity",
"state": "humidity",
"unit": "%",
}
SENSOR_MOTION = {
FEATURE_MOTION = {
"id": "motion",
"name": "Motion",
"state": "get_motion",
"state": "motion",
"unit": "state",
}
SENSOR_PING = {
FEATURE_PING = {
"id": "ping",
"name": "Ping roundtrip",
"state": "get_ping",
"state": "ping",
"unit": TIME_MILLISECONDS,
}
SENSOR_POWER_USE = {
FEATURE_POWER_USE = {
"id": "power_1s",
"name": "Power usage",
"state": "get_power_usage",
"state": "current_power_usage",
"unit": POWER_WATT,
}
SENSOR_POWER_USE_LAST_8_SEC = {
FEATURE_POWER_USE_LAST_8_SEC = {
"id": "power_8s",
"name": "Power usage 8 seconds",
"state": "get_power_usage_8_sec",
"state": "current_power_usage_8_sec",
"unit": POWER_WATT,
}
SENSOR_POWER_CONSUMPTION_CURRENT_HOUR = {
FEATURE_POWER_CONSUMPTION_CURRENT_HOUR = {
"id": "power_con_cur_hour",
"name": "Power consumption current hour",
"state": "get_power_consumption_current_hour",
"state": "power_consumption_current_hour",
"unit": ENERGY_KILO_WATT_HOUR,
}
SENSOR_POWER_CONSUMPTION_PREVIOUS_HOUR = {
FEATURE_POWER_CONSUMPTION_PREVIOUS_HOUR = {
"id": "power_con_prev_hour",
"name": "Power consumption previous hour",
"state": "get_power_consumption_previous_hour",
"state": "power_consumption_previous_hour",
"unit": ENERGY_KILO_WATT_HOUR,
}
SENSOR_POWER_CONSUMPTION_TODAY = {
FEATURE_POWER_CONSUMPTION_TODAY = {
"id": "power_con_today",
"name": "Power consumption today",
"state": "get_power_consumption_today",
"state": "power_consumption_today",
"unit": ENERGY_KILO_WATT_HOUR,
}
SENSOR_POWER_CONSUMPTION_YESTERDAY = {
FEATURE_POWER_CONSUMPTION_YESTERDAY = {
"id": "power_con_yesterday",
"name": "Power consumption yesterday",
"state": "get_power_consumption_yesterday",
"state": "power_consumption_yesterday",
"unit": ENERGY_KILO_WATT_HOUR,
}
SENSOR_POWER_PRODUCTION_CURRENT_HOUR = {
FEATURE_POWER_PRODUCTION_CURRENT_HOUR = {
"id": "power_prod_cur_hour",
"name": "Power production current hour",
"state": "get_power_production_current_hour",
"state": "power_production_current_hour",
"unit": ENERGY_KILO_WATT_HOUR,
}
SENSOR_POWER_PRODUCTION_PREVIOUS_HOUR = {
FEATURE_POWER_PRODUCTION_PREVIOUS_HOUR = {
"id": "power_prod_prev_hour",
"name": "Power production previous hour",
"state": "get_power_production_previous_hour",
"state": "power_production_previous_hour",
"unit": ENERGY_KILO_WATT_HOUR,
}
SENSOR_SWITCH = {
FEATURE_RELAY = {
"id": "relay",
"name": "Relay state",
"state": "relay_state",
"unit": "state",
}
FEATURE_SWITCH = {
"id": "switch",
"name": "switch",
"state": "get_switch_state",
"name": "Switch state",
"state": "switch_state",
"unit": "state",
}
SENSOR_TEMPERATURE = {
FEATURE_TEMPERATURE = {
"id": "temperature",
"name": "Temperature",
"state": "get_temperature",
"state": "temperature",
"unit": TEMP_CELSIUS,
}

# TODO: Need to validate RSSI sensors
SENSOR_RSSI_IN = {
FEATURE_RSSI_IN = {
"id": "RSSI_in",
"name": "RSSI in",
"state": "get_rssi_in",
"state": "rssi_in",
"unit": "Unknown",
}
SENSOR_RSSI_OUT = {
FEATURE_RSSI_OUT = {
"id": "RSSI_out",
"name": "RSSI out",
"state": "get_rssi_out",
"state": "rssi_out",
"unit": "Unknown",
}

# Switches
SWITCH_RELAY = {
"id": "relay",
"name": "Relay state",
"state": "get_relay_state",
"switch": "set_relay_state",
}

# Home Assistant entities
HA_SWITCH = "switch"
HA_SENSOR = "sensor"
HA_BINARY_SENSOR = "binary_sensor"


### Smile constants ###

APPLIANCES = "/core/appliances"
Expand Down
43 changes: 29 additions & 14 deletions plugwise/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
- handle the connection (connect/disconnect) to the USB-Stick
- take care for message acknowledgements based on sequence id's
- resend message requests when timeouts occurs
- holds a sending queue (fifo)
- holds a sending queue and submit messages based on the message priority (high, medium, low)
- passes received messages back to message processor (stick.py)
- execution of callbacks after processing the response message

"""

from datetime import datetime, timedelta
import logging
import queue
from queue import Empty, PriorityQueue
import threading
import time

Expand All @@ -22,6 +22,7 @@
from .constants import (
MESSAGE_RETRY,
MESSAGE_TIME_OUT,
PRIORITY_MEDIUM,
REQUEST_FAILED,
REQUEST_SUCCESS,
SLEEP_TIME,
Expand Down Expand Up @@ -62,7 +63,7 @@ def connect_to_stick(self, callback=None) -> bool:
"""
Connect to USB-Stick and startup all worker threads

Return: True when if successfully.
Return: True when connection is successful.
"""
self.init_callback = callback
# Open connection to USB Stick
Expand All @@ -77,7 +78,7 @@ def connect_to_stick(self, callback=None) -> bool:
if self.connection.connect():
_LOGGER.debug("Starting message controller threads...")
# send daemon
self._send_message_queue = queue.Queue()
self._send_message_queue = PriorityQueue()
self._run_send_message_thread = True
self._send_message_thread = threading.Thread(
None, self._send_message_loop, "send_messages_thread", (), {}
Expand All @@ -96,20 +97,32 @@ def connect_to_stick(self, callback=None) -> bool:
_LOGGER.warning("Failed to connect to USB stick")
return self.connection.is_connected()

def send(self, request: NodeRequest, callback=None, retry_counter=0):
def send(
self,
request: NodeRequest,
callback=None,
retry_counter=0,
priority=PRIORITY_MEDIUM,
):
"""Queue request message to be sent into Plugwise Zigbee network."""
_LOGGER.debug(
"Queue %s to be send with retry counter %s",
"Queue %s to be send with retry counter %s and priority %s",
request.__class__.__name__,
str(retry_counter),
str(priority),
)
self._send_message_queue.put(
[
request,
callback,
(
priority,
retry_counter,
None,
]
datetime.now(),
[
request,
callback,
retry_counter,
None,
],
)
)

def resend(self, seq_id):
Expand Down Expand Up @@ -142,7 +155,7 @@ def resend(self, seq_id):
if self.expected_responses[seq_id][1]:
self.expected_responses[seq_id][1]()
else:
_LOGGER.warning(
_LOGGER.info(
"Resend %s for %s, retry %s of %s",
_request,
_mac,
Expand Down Expand Up @@ -180,8 +193,10 @@ def _send_message_loop(self):
"""Daemon to send messages waiting in queue."""
while self._run_send_message_thread:
try:
request_set = self._send_message_queue.get(block=True, timeout=1)
except queue.Empty:
_prio, _retry, _dt, request_set = self._send_message_queue.get(
block=True, timeout=1
)
except Empty:
time.sleep(SLEEP_TIME)
else:
# Calc next seq_id based last received ack message
Expand Down
2 changes: 1 addition & 1 deletion plugwise/messages/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ class NodeFeaturesResponse(NodeResponse):

def __init__(self):
super().__init__()
self.features = Int(0, 16)
self.features = String(None, length=16)
self.params += [self.features]


Expand Down
Loading