Skip to content

Commit 999044e

Browse files
authored
Merge pull request #247 from plugwise/enable_production
Implement enable/disable production services
2 parents e413070 + a628fed commit 999044e

8 files changed

Lines changed: 138 additions & 30 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Versions from 0.4x
44

5+
### v0.51.0
6+
7+
- Bump plugwise to [v0.41.0](https://github.com/plugwise/python-plugwise-usb/releases/tag/v0.41.0)
8+
- Implement services for enabling/disabling of production logging ([#247](https://github.com/plugwise/plugwise_usb-beta/pull/247))
9+
510
### v0.50.1
611

712
- Fix error in Number platform

custom_components/plugwise_usb/__init__.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55
from typing import Any, TypedDict
66

7+
from homeassistant.components.device_tracker import ATTR_MAC
78
from homeassistant.core import HomeAssistant, ServiceCall, callback
89
from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError
910
from homeassistant.helpers import device_registry as dr, entity_registry as er
@@ -18,6 +19,9 @@
1819
NODES,
1920
PLUGWISE_USB_PLATFORMS,
2021
SERVICE_AUTO_JOIN,
22+
SERVICE_DISABLE_PRODUCTION,
23+
SERVICE_ENABLE_PRODUCTION,
24+
SERVICE_USB_DEVICE_SCHEMA,
2125
STICK,
2226
)
2327
from .coordinator import PlugwiseUSBConfigEntry, PlugwiseUSBDataUpdateCoordinator
@@ -124,7 +128,31 @@ async def enable_auto_joining(call: ServiceCall) -> bool:
124128
raise HomeAssistantError(f"Failed to enable auto-joining: {exc}") from exc
125129
return result
126130

131+
async def enable_production(call: ServiceCall) -> bool:
132+
"""Enable production-logging for a Node."""
133+
mac = call.data[ATTR_MAC]
134+
try:
135+
result = await api_stick.set_energy_intervals(mac, 60, 60)
136+
except (NodeError, StickError) as exc:
137+
raise HomeAssistantError(f"Failed to enable production: {exc}") from exc
138+
return result
139+
140+
async def disable_production(call: ServiceCall) -> bool:
141+
"""Disable production-logging for a Node."""
142+
mac = call.data[ATTR_MAC]
143+
try:
144+
result = await api_stick.set_energy_intervals(mac, 60, 0)
145+
except (NodeError, StickError) as exc:
146+
raise HomeAssistantError(f"Failed to disable production: {exc}") from exc
147+
return result
148+
127149
hass.services.async_register(DOMAIN, SERVICE_AUTO_JOIN, enable_auto_joining)
150+
hass.services.async_register(
151+
DOMAIN, SERVICE_ENABLE_PRODUCTION, enable_production, SERVICE_USB_DEVICE_SCHEMA
152+
)
153+
hass.services.async_register(
154+
DOMAIN, SERVICE_DISABLE_PRODUCTION, disable_production, SERVICE_USB_DEVICE_SCHEMA
155+
)
128156

129157
# Initiate background nodes discovery task
130158
config_entry.async_create_task(

custom_components/plugwise_usb/const.py

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,50 @@
55

66
import voluptuous as vol
77

8+
from homeassistant.components.device_tracker import ATTR_MAC
89
from homeassistant.const import Platform
910
from homeassistant.helpers import config_validation as cv
1011

11-
DOMAIN: Final = "plugwise_usb"
12+
DOMAIN: Final[str] = "plugwise_usb"
1213

1314
LOGGER = logging.getLogger(__package__)
14-
UNSUB_NODE_LOADED: Final = "Unsubcribe_from_node_loaded_event"
15-
COORDINATOR: Final = "coordinator"
16-
CONF_MANUAL_PATH: Final = "Enter Manually"
17-
MANUAL_PATH: Final = "manual_path"
18-
STICK: Final = "stick"
19-
NODES: Final = "nodes"
20-
USB: Final = "usb"
15+
UNSUB_NODE_LOADED: Final[str] = "Unsubcribe_from_node_loaded_event"
16+
COORDINATOR: Final[str] = "coordinator"
17+
CONF_MANUAL_PATH: Final[str] = "Enter Manually"
18+
MANUAL_PATH: Final[str] = "manual_path"
19+
STICK: Final[str] = "stick"
20+
NODES: Final[str] = "nodes"
21+
USB: Final[str] = "usb"
2122

22-
UNDO_UPDATE_LISTENER: Final = "undo_update_listener"
23+
UNDO_UPDATE_LISTENER: Final[str] = "undo_update_listener"
2324

2425
PLUGWISE_USB_PLATFORMS: Final[list[str]] = [
2526
Platform.BINARY_SENSOR,
2627
Platform.NUMBER,
2728
Platform.SENSOR,
2829
Platform.SWITCH,
2930
]
30-
CONF_USB_PATH: Final = "usb_path"
31-
32-
ATTR_MAC_ADDRESS: Final = "mac"
33-
34-
SERVICE_AUTO_JOIN: Final = "enable_auto_joining"
31+
CONF_USB_PATH: Final[str] = "usb_path"
32+
SERVICE_AUTO_JOIN: Final[str] = "enable_auto_joining"
33+
SERVICE_DISABLE_PRODUCTION: Final[str] = "disable_production"
34+
SERVICE_ENABLE_PRODUCTION: Final[str] = "enable_production"
3535
SERVICE_USB_DEVICE_SCHEMA: Final = vol.Schema(
36-
{vol.Required(ATTR_MAC_ADDRESS): cv.string}
36+
{
37+
vol.Required(ATTR_MAC): vol.All(
38+
cv.string,
39+
vol.Match(r"^[0-9A-Fa-f]{16}$")
40+
)
41+
}
3742
)
3843

3944
# USB SED (battery powered) device constants
40-
ATTR_SED_STAY_ACTIVE: Final = "stay_active"
41-
ATTR_SED_SLEEP_FOR: Final = "sleep_for"
42-
ATTR_SED_MAINTENANCE_INTERVAL: Final = "maintenance_interval"
43-
ATTR_SED_CLOCK_SYNC: Final = "clock_sync"
44-
ATTR_SED_CLOCK_INTERVAL: Final = "clock_interval"
45+
ATTR_SED_STAY_ACTIVE: Final[str] = "stay_active"
46+
ATTR_SED_SLEEP_FOR: Final[str] = "sleep_for"
47+
ATTR_SED_MAINTENANCE_INTERVAL: Final[str] = "maintenance_interval"
48+
ATTR_SED_CLOCK_SYNC: Final[str] = "clock_sync"
49+
ATTR_SED_CLOCK_INTERVAL: Final[str] = "clock_interval"
4550

46-
SERVICE_USB_SED_BATTERY_CONFIG: Final = "configure_battery_savings"
51+
SERVICE_USB_SED_BATTERY_CONFIG: Final[str] = "configure_battery_savings"
4752
SERVICE_USB_SED_BATTERY_CONFIG_SCHEMA: Final = {
4853
vol.Required(ATTR_SED_STAY_ACTIVE): vol.All(
4954
vol.Coerce(int), vol.Range(min=1, max=120)
@@ -62,20 +67,20 @@
6267

6368

6469
# USB Scan device constants
65-
ATTR_SCAN_DAYLIGHT_MODE: Final = "day_light"
66-
ATTR_SCAN_SENSITIVITY_MODE: Final = "sensitivity_mode"
67-
ATTR_SCAN_RESET_TIMER: Final = "reset_timer"
70+
ATTR_SCAN_DAYLIGHT_MODE: Final[str] = "day_light"
71+
ATTR_SCAN_SENSITIVITY_MODE: Final[str] = "sensitivity_mode"
72+
ATTR_SCAN_RESET_TIMER: Final[str] = "reset_timer"
6873

69-
SCAN_SENSITIVITY_HIGH: Final = "high"
70-
SCAN_SENSITIVITY_MEDIUM: Final = "medium"
71-
SCAN_SENSITIVITY_OFF: Final = "off"
74+
SCAN_SENSITIVITY_HIGH: Final[str] = "high"
75+
SCAN_SENSITIVITY_MEDIUM: Final[str] = "medium"
76+
SCAN_SENSITIVITY_OFF: Final[str] = "off"
7277
SCAN_SENSITIVITY_MODES = [
7378
SCAN_SENSITIVITY_HIGH,
7479
SCAN_SENSITIVITY_MEDIUM,
7580
SCAN_SENSITIVITY_OFF,
7681
]
7782

78-
SERVICE_USB_SCAN_CONFIG: Final = "configure_scan"
83+
SERVICE_USB_SCAN_CONFIG: Final[str] = "configure_scan"
7984
SERVICE_USB_SCAN_CONFIG_SCHEMA = (
8085
{
8186
vol.Required(ATTR_SCAN_SENSITIVITY_MODE): vol.In(SCAN_SENSITIVITY_MODES),

custom_components/plugwise_usb/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"integration_type": "hub",
99
"iot_class": "local_polling",
1010
"loggers": ["plugwise_usb"],
11-
"requirements": ["plugwise-usb==0.40.0"],
12-
"version": "0.50.2"
11+
"requirements": ["plugwise-usb==0.41.0"],
12+
"version": "0.51.0"
1313
}

custom_components/plugwise_usb/services.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
enable_auto_joining:
22
description: First enable auto-joining, then reset the Plugwise devices
3+
enable_production:
4+
description: "Enable production logging for a Plugwise USB node by MAC address"
5+
fields:
6+
mac:
7+
example: "data: {mac: 0123456789ABCDEF}"
8+
disable_production:
9+
description: "Disable production logging for a Plugwise USB node by MAC address"
10+
fields:
11+
mac:
12+
example: "data: {mac: 0123456789ABCDEF}"
313
configure_scan:
414
fields:
515
entity_id:

custom_components/plugwise_usb/strings.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@
2727
"name": "Enable Plugwise device auto-joining (temporarily)",
2828
"description": "First enable this service then reset the Plugwise device(s) to join"
2929
},
30+
"enable_production":{
31+
"name": "Enable production logging",
32+
"description": "Enter the mac of the Node: (data = mac: 0123456789ABCDEF)",
33+
"fields": {
34+
"mac": {
35+
"name": "MAC address",
36+
"description": "The full 16 character MAC address of the plugwise device."
37+
}
38+
}
39+
},
40+
"disable_production":{
41+
"name": "Disable production logging, return to consumption logging only",
42+
"description": "Enter the mac of the Node: (data = mac: 0123456789ABCDEF)",
43+
"fields": {
44+
"mac": {
45+
"name": "MAC address",
46+
"description": "The full 16 character MAC address of the plugwise device."
47+
}
48+
}
49+
},
3050
"configure_scan": {
3151
"name": "Configure motion settings",
3252
"description": "Configure the motion settings for a Plugwise Scan device. The new configuration will be send soon as the Scan devices is awake to receive configuration changes. For quick activation press the local button to awake the device.",

custom_components/plugwise_usb/translations/en.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@
2727
"name": "Enable Plugwise device auto-joining (temporarily)",
2828
"description": "First enable this service then reset the Plugwise device(s) to join"
2929
},
30+
"enable_production":{
31+
"name": "Enable production logging",
32+
"description": "Enter the mac of the Node: (data = mac: 0123456789ABCDEF)",
33+
"fields": {
34+
"mac": {
35+
"name": "MAC address",
36+
"description": "The full 16 character MAC address of the plugwise device."
37+
}
38+
}
39+
},
40+
"disable_production":{
41+
"name": "Disable production logging, return to consumption logging only",
42+
"description": "Enter the mac of the Node: (data = mac: 0123456789ABCDEF)",
43+
"fields": {
44+
"mac": {
45+
"name": "MAC address",
46+
"description": "The full 16 character MAC address of the plugwise device."
47+
}
48+
}
49+
},
3050
"configure_scan": {
3151
"name": "Configure motion settings",
3252
"description": "Configure the motion settings for a Plugwise Scan device. The new configuration will be send soon as the Scan devices is awake to receive configuration changes. For quick activation press the local button to awake the device.",

custom_components/plugwise_usb/translations/nl.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@
2727
"name": "Zet Plugwise auto-toevoegen aan (tijdelijk)",
2828
"description": "Voer eerst deze service uit en reset dan het toe te voegen Plugwise apparaat"
2929
},
30+
"enable_production":{
31+
"name": "Zet productie-loggen aan",
32+
"description": "Voer het mac-adres van de Node in: (data = mac: 0123456789ABSDEF)",
33+
"fields": {
34+
"mac": {
35+
"name": "MAC adres",
36+
"description": "Het volledige MAC address (16 karakters) van het plugwise apparaat."
37+
}
38+
}
39+
},
40+
"disable_production":{
41+
"name": "Zet productie-loggen uit, alleen consumptie-loggen actief",
42+
"description": "Voer het mac-adres van de Node in: (data = mac: 0123456789ABSDEF)",
43+
"fields": {
44+
"mac": {
45+
"name": "MAC adres",
46+
"description": "Het volledige MAC address (16 karakters) van het plugwise apparaat."
47+
}
48+
}
49+
},
3050
"configure_scan": {
3151
"name": "Configureer bewegingsinstellingen voor een Plugwise Scan apparaat",
3252
"description": "Configureert bewegingsinstellingen voor een Plugwise Scan apparaat.",

0 commit comments

Comments
 (0)