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
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Changelog

## Ongoing
## v1.7.7

- Implement code quality improvements as suggested by SonarCloud
- Implement code quality improvements as suggested by SonarCloud via [#762](https://github.com/plugwise/python-plugwise/pull/762), [#763](https://github.com/plugwise/python-plugwise/pull/763), [#764](https://github.com/plugwise/python-plugwise/pull/764), and [#765](https://github.com/plugwise/python-plugwise/pull/765)

## v1.7.6

Expand Down
11 changes: 11 additions & 0 deletions plugwise/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from plugwise.constants import (
ANNA,
NONE,
PRIORITY_DEVICE_CLASSES,
SPECIAL_PLUG_TYPES,
SWITCH_GROUP_TYPES,
ApplianceType,
Expand Down Expand Up @@ -152,6 +153,16 @@ def _create_gw_entities(self, appl: Munch) -> None:
self.gw_entities[appl.entity_id][appl_key] = value
self._count += 1

def _reorder_devices(self) -> None:
"""Place the gateway and optional heater_central devices as 1st and 2nd."""
reordered = {}
for dev_class in PRIORITY_DEVICE_CLASSES:
for entity_id, entity in dict(self.gw_entities).items():
if entity["dev_class"] == dev_class:
reordered[entity_id] = self.gw_entities.pop(entity_id)
break
self.gw_entities = {**reordered, **self.gw_entities}

def _entity_switching_group(self, entity: GwEntityData, data: GwEntityData) -> None:
"""Helper-function for _get_device_zone_data().

Expand Down
2 changes: 1 addition & 1 deletion plugwise/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
MODULE_LOCATOR: Final = "./logs/point_log/*[@id]"
NONE: Final = "None"
OFF: Final = "off"
PRIORITY_DEVICE_CLASSES = ("heater_central", "gateway")
PRIORITY_DEVICE_CLASSES = ("gateway", "heater_central")

# XML data paths
APPLIANCES: Final = "/core/appliances"
Expand Down
15 changes: 1 addition & 14 deletions plugwise/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
NONE,
OFF,
P1_MEASUREMENTS,
PRIORITY_DEVICE_CLASSES,
TEMP_CELSIUS,
THERMOSTAT_CLASSES,
TOGGLES,
Expand Down Expand Up @@ -160,7 +159,7 @@ def _all_appliances(self) -> None:
self._get_p1_smartmeter_info()

# Sort the gw_entities
self._sort_gw_entities()
self._reorder_devices()

def _get_p1_smartmeter_info(self) -> None:
"""For P1 collect the connected SmartMeter info from the Home/building location.
Expand Down Expand Up @@ -193,18 +192,6 @@ def _get_p1_smartmeter_info(self) -> None:

self._create_gw_entities(appl)

def _sort_gw_entities(self) -> None:
"""Place the gateway and optional heater_central entities as 1st and 2nd."""
for dev_class in PRIORITY_DEVICE_CLASSES:
for entity_id, entity in dict(self.gw_entities).items():
if entity["dev_class"] == dev_class:
priority_entity = entity
self.gw_entities.pop(entity_id)
other_entities = self.gw_entities
priority_entities = {entity_id: priority_entity}
self.gw_entities = {**priority_entities, **other_entities}
break

def _all_locations(self) -> None:
"""Collect all locations."""
loc = Munch()
Expand Down
13 changes: 1 addition & 12 deletions plugwise/legacy/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
NONE,
OFF,
P1_LEGACY_MEASUREMENTS,
PRIORITY_DEVICE_CLASSES,
TEMP_CELSIUS,
THERMOSTAT_CLASSES,
UOM,
Expand Down Expand Up @@ -136,17 +135,7 @@ def _all_appliances(self) -> None:
continue # pragma: no cover

self._create_gw_entities(appl)

# Place the gateway and optional heater_central devices as 1st and 2nd
for dev_class in PRIORITY_DEVICE_CLASSES:
for entity_id, entity in dict(self.gw_entities).items():
if entity["dev_class"] == dev_class:
tmp_entity = entity
self.gw_entities.pop(entity_id)
cleared_dict = self.gw_entities
add_to_front = {entity_id: tmp_entity}
self.gw_entities = {**add_to_front, **cleared_dict}
break
self._reorder_devices()

def _all_locations(self) -> None:
"""Collect all locations."""
Expand Down
36 changes: 22 additions & 14 deletions plugwise/smile.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@
from munch import Munch


def model_to_switch_items(model: str, state: str, switch: Munch) -> tuple[str, Munch]:
"""Translate state and switch attributes based on model name.

Helper function for set_switch_state().
"""
match model:
case "dhw_cm_switch":
switch.device = "toggle"
switch.func_type = "toggle_functionality"
switch.act_type = "domestic_hot_water_comfort_mode"
case "cooling_ena_switch":
switch.device = "toggle"
switch.func_type = "toggle_functionality"
switch.act_type = "cooling_enabled"
case "lock":
switch.func = "lock"
state = "true" if state == STATE_ON else "false"

return state, switch


class SmileAPI(SmileData):
"""The Plugwise SmileAPI helper class for actual Plugwise devices."""

Expand Down Expand Up @@ -381,20 +402,7 @@ async def set_switch_state(
switch.device = "relay"
switch.func_type = "relay_functionality"
switch.func = "state"
if model == "dhw_cm_switch":
switch.device = "toggle"
switch.func_type = "toggle_functionality"
switch.act_type = "domestic_hot_water_comfort_mode"

if model == "cooling_ena_switch":
switch.device = "toggle"
switch.func_type = "toggle_functionality"
switch.act_type = "cooling_enabled"

if model == "lock":
switch.func = "lock"
state = "true" if state == STATE_ON else "false"

state, switch = model_to_switch_items(model, state, switch)
data = (
f"<{switch.func_type}>"
f"<{switch.func}>{state}</{switch.func}>"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "plugwise"
version = "1.7.6"
version = "1.7.7"
license = "MIT"
description = "Plugwise Smile (Adam/Anna/P1) and Stretch module for Python 3."
readme = "README.md"
Expand Down
Loading