Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name: Latest commit

env:
CACHE_VERSION: 1
CACHE_VERSION: 3
DEFAULT_PYTHON: "3.9"
PRE_COMMIT_HOME: ~/.cache/pre-commit

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
build.sh
.DS_Store
*.pyc
.*.swp
__pycache__
/dist/
/*.egg-info
Expand Down
21 changes: 17 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
repos:
# Run manually in CI skipping the branch checks
- repo: https://github.com/PyCQA/pylint
rev: v2.12.2
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
args:
[
"-rn", # Only display messages
"-sn", # Don't display the score
]
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
Expand Down Expand Up @@ -75,7 +92,3 @@ repos:
types: [python]
require_serial: true
files: ^plugwise/.+\.py$
# - repo: https://github.com/PyCQA/isort
# rev: 5.10.1
# hooks:
# - id: isort
12 changes: 7 additions & 5 deletions plugwise/connections/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, port, parser):
self._writer_thread = None

################################################
### Open connection ###
# Open connection #
################################################

def connect(self) -> bool:
Expand All @@ -40,7 +40,7 @@ def _open_connection(self):
"""Placeholder."""

################################################
### Reader ###
# Reader #
################################################

def _reader_start(self, name):
Expand All @@ -58,12 +58,14 @@ def _reader_deamon(self):
time.sleep(0.01)
_LOGGER.debug("Reader daemon stopped")

# TODO: 20220125 function instead of self
# pylint: disable=no-self-use
def _read_data(self):
"""placeholder."""
return b"0000"

################################################
### Writer ###
# Writer #
################################################

def _writer_start(self, name: str):
Expand Down Expand Up @@ -101,7 +103,7 @@ def send(self, message: NodeRequest, callback=None):
self._write_queue.put_nowait((message, callback))

################################################
### Connection state ###
# Connection state #
################################################

def is_connected(self):
Expand All @@ -117,7 +119,7 @@ def write_thread_alive(self):
return self._writer_thread.is_alive() if self.run_writer_thread else False

################################################
### Close connection ###
# Close connection #
################################################

def disconnect(self):
Expand Down
6 changes: 1 addition & 5 deletions plugwise/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,7 @@ def message_handler(self, message):
else:
self._log_status_message(message)
self.message_processor(message)
if (
message.seq_id != b"FFFF"
and message.seq_id != b"FFFE"
and message.seq_id != b"FFFD"
):
if message.seq_id not in [b"FFFF", b"FFFE", b"FFFD"]:
self._post_message_action(
message.seq_id, None, message.__class__.__name__
)
Expand Down
52 changes: 38 additions & 14 deletions plugwise/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

# This way of importing aiohttp is because of patch/mocking in testing (aiohttp timeouts)
from aiohttp import BasicAuth, ClientSession, ClientTimeout, ServerTimeoutError
from dateutil import tz
from dateutil.parser import parse
from defusedxml import ElementTree as etree
from munch import Munch
Expand All @@ -17,24 +16,16 @@

from .constants import (
APPLIANCES,
ATTR_ICON,
ATTR_ID,
ATTR_NAME,
ATTR_STATE,
ATTR_TYPE,
ATTR_UNIT_OF_MEASUREMENT,
BINARY_SENSORS,
COOLING_ICON,
DEVICE_MEASUREMENTS,
DOMAIN_OBJECTS,
ENERGY_KILO_WATT_HOUR,
ENERGY_WATT_HOUR,
FAKE_LOC,
FLAME_ICON,
HEATER_CENTRAL_MEASUREMENTS,
HEATING_ICON,
HOME_MEASUREMENTS,
IDLE_ICON,
LOCATIONS,
POWER_WATT,
SENSORS,
Expand All @@ -49,7 +40,6 @@
ResponseError,
)
from .util import (
determine_selected,
escape_illegal_xml_characters,
format_measure,
in_between,
Expand Down Expand Up @@ -165,9 +155,9 @@ def schemas_schedule_temp(schedules, name):
for i in range(length):
result_1 = schema_list[i][0]
start = schema_list[i][1]
n = (i + 1) % (length - 1)
result_2 = schema_list[n][0]
end = schema_list[n][1]
j = (i + 1) % (length - 1)
result_2 = schema_list[j][0]
end = schema_list[j][1]
now = dt.datetime.now().time()
if (
result_1 == dt.datetime.now().weekday()
Expand Down Expand Up @@ -326,6 +316,39 @@ async def close_connection(self):
class SmileHelper:
"""The SmileHelper class."""

def __init__(self):
"""Set the constructor for this class."""
self._appl_data = None
self._appliances = None
self._cooling_present = None
self._cp_state = None
self._devices = None
self._domain_objects = None
self._heater_id = None
self._home_location = None
self._last_active = {}
self._loc_data = None
self._locations = None
self._modules = None
self._on_off_device = None
self._ot_device = None
self._outdoor_temp = None
self._sm_thermostat = None
self._thermo_locs = None

self._smile_legacy = None
self._stretch_v2 = None
self._stretch_v3 = None

self.cooling_active = None
self.gateway_id = None
self.gw_data = {}
self.gw_devices = {}

self.smile_name = None
self.smile_type = None
self.smile_version = []

def _locations_legacy(self):
"""Helper-function for _all_locations().
Create locations for legacy devices.
Expand Down Expand Up @@ -420,7 +443,8 @@ def _get_module_data(self, appliance, locator, mod_type):
if appl_search is not None:
link_id = appl_search.attrib["id"]
locator = f".//{mod_type}[@id='{link_id}']...."
if (module := self._modules.find(locator)) is not None:
module = self._modules.find(locator)
if module is not None:
v_name = module.find("vendor_name").text
v_model = module.find("vendor_model").text
hw_version = module.find("hardware_version").text
Expand Down
4 changes: 3 additions & 1 deletion plugwise/messages/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def deserialize(self, response):
self.msg_id = response[4:8]
self.seq_id = response[8:12]
response = response[12:]
if self.format_size == MESSAGE_SMALL or self.format_size == MESSAGE_LARGE:
if self.format_size in [MESSAGE_SMALL, MESSAGE_LARGE]:
self.ack_id = response[:4]
response = response[4:]
if self.format_size != MESSAGE_SMALL:
Expand Down Expand Up @@ -337,6 +337,8 @@ def __init__(self):
self.datetime = DateTime()
self.last_logaddr = LogAddr(0, length=8)
self.relay_state = Int(0, length=2)
# TODO: 20220126 snake-style
# pylint: disable=invalid-name
self.hz = Int(0, length=2)
self.hw_ver = String(None, length=12)
self.fw_ver = UnixTimestamp(0)
Expand Down
13 changes: 7 additions & 6 deletions plugwise/nodes/circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,9 @@ def _response_energy_counters(self, message: CircleEnergyCountersResponse):
self._energy_last_populated_slot = _slot

# Store most recent timestamp of collected pulses
if self._energy_last_collected_timestamp < _log_timestamp:
self._energy_last_collected_timestamp = _log_timestamp
self._energy_last_collected_timestamp = max(
self._energy_last_collected_timestamp, _log_timestamp
)

# Trigger history rollover
if (
Expand Down Expand Up @@ -746,11 +747,11 @@ def _response_energy_counters(self, message: CircleEnergyCountersResponse):
)
self._update_energy_today_now(False, _history_rollover, _midnight_rollover)
else:
_LOGGER.info(
"_response_energy_counters for %s | self._energy_history_collecting running",
self.mac,
str(_local_midnight_timestamp),
logstring = (
"_response_energy_counters for %s | self._energy_history_collecting running %s"
% (self.mac, str(_local_midnight_timestamp))
)
_LOGGER.info(logstring)

# Cleanup energy history for more than 8 day's ago
_8_days_ago = datetime.utcnow().replace(
Expand Down
6 changes: 6 additions & 0 deletions plugwise/nodes/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,14 @@ def _process_switch_group(self, message):
self.mac,
)

# TODO: 20220125 snakestyle name
# pylint: disable=invalid-name
def CalibrateLight(self, callback=None):
"""Queue request to calibration light sensitivity"""
self._queue_request(ScanLightCalibrateRequest(self._mac), callback)

# TODO: 20220125 snakestyle name
# pylint: disable=invalid-name
def Configure_scan(
self,
motion_reset_timer=SCAN_MOTION_RESET_TIMER,
Expand All @@ -126,6 +130,8 @@ def Configure_scan(
callback,
)

# TODO: 20220125 snakestyle name
# pylint: disable=invalid-name
def SetMotionAction(self, callback=None):
"""Queue Configure Scan to signal motion"""
# TODO:
Expand Down
17 changes: 9 additions & 8 deletions plugwise/nodes/sed.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,13 @@ def _process_awake_response(self, message):
str(message.awake_type.value),
self.mac,
)
if (
message.awake_type.value == SED_AWAKE_MAINTENANCE
or message.awake_type.value == SED_AWAKE_FIRST
or message.awake_type.value == SED_AWAKE_STARTUP
or message.awake_type.value == SED_AWAKE_BUTTON
):
for request in self._sed_requests:
(request_message, callback) = self._sed_requests[request]
if message.awake_type.value in [
SED_AWAKE_MAINTENANCE,
SED_AWAKE_FIRST,
SED_AWAKE_STARTUP,
SED_AWAKE_BUTTON,
]:
for request_message, callback in self._sed_requests.items():
_LOGGER.info(
"Send queued %s message to SED node %s",
request_message.__class__.__name__,
Expand Down Expand Up @@ -136,6 +135,8 @@ def _wake_up_interval_accepted(self):
"""Callback after wake up interval is received and accepted by SED."""
self._wake_up_interval = self._new_maintenance_interval

# TODO: 20220125 snakestyle name
# pylint: disable=invalid-name
def Configure_SED(
self,
stay_active=SED_STAY_ACTIVE,
Expand Down
Loading