Skip to content

Commit 5f9778c

Browse files
committed
Formatr files
1 parent 137a6d1 commit 5f9778c

File tree

8 files changed

+57
-39
lines changed

8 files changed

+57
-39
lines changed

custom_components/plugwise_usb/__init__.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Support for Plugwise devices connected to a Plugwise USB-stick."""
2+
23
import logging
34
from typing import Any, TypedDict
45

@@ -29,11 +30,15 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
2930
"""Establish connection with plugwise USB-stick."""
3031

3132
@callback
32-
def _async_migrate_entity_entry(entity_entry: er.RegistryEntry) -> dict[str, Any] | None:
33+
def _async_migrate_entity_entry(
34+
entity_entry: er.RegistryEntry,
35+
) -> dict[str, Any] | None:
3336
"""Migrate Plugwise entity entry."""
3437
return async_migrate_entity_entry(config_entry, entity_entry)
3538

36-
await er.async_migrate_entries(hass, config_entry.entry_id, _async_migrate_entity_entry)
39+
await er.async_migrate_entries(
40+
hass, config_entry.entry_id, _async_migrate_entity_entry
41+
)
3742

3843
api_stick = Stick(config_entry.data[CONF_USB_PATH])
3944
api_stick.cache_folder = hass.config.path(
@@ -75,19 +80,15 @@ async def async_node_discovered(node_event: NodeEvent, mac: str) -> None:
7580
await api_stick.discover_coordinator(load=False)
7681
except StickError:
7782
await api_stick.disconnect()
78-
raise ConfigEntryNotReady(
79-
"Failed to connect to Circle+"
80-
) from StickError
83+
raise ConfigEntryNotReady("Failed to connect to Circle+") from StickError
8184

8285
# Load platforms to allow them to register for node events
8386
await hass.config_entries.async_forward_entry_setups(
8487
config_entry, PLUGWISE_USB_PLATFORMS
8588
)
8689

8790
# Initiate background discovery task
88-
hass.async_create_task(
89-
api_stick.discover_nodes(load=True)
90-
)
91+
hass.async_create_task(api_stick.discover_nodes(load=True))
9192
return True
9293

9394

custom_components/plugwise_usb/binary_sensor.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Plugwise USB Binary Sensor component for Home Assistant."""
2+
23
from __future__ import annotations
34

45
from dataclasses import dataclass
@@ -25,7 +26,9 @@
2526

2627

2728
@dataclass(kw_only=True)
28-
class PlugwiseBinarySensorEntityDescription(PlugwiseUSBEntityDescription, BinarySensorEntityDescription):
29+
class PlugwiseBinarySensorEntityDescription(
30+
PlugwiseUSBEntityDescription, BinarySensorEntityDescription
31+
):
2932
"""Describes Plugwise binary sensor entity."""
3033

3134

@@ -52,7 +55,9 @@ async def async_add_binary_sensor(node_event: NodeEvent, mac: str) -> None:
5255
return
5356
entities: list[PlugwiseUSBEntity] = []
5457
if (node_duc := config_entry.runtime_data[NODES].get(mac)) is not None:
55-
_LOGGER.debug("Add binary_sensor entities for %s | duc=%s", mac, node_duc.name)
58+
_LOGGER.debug(
59+
"Add binary_sensor entities for %s | duc=%s", mac, node_duc.name
60+
)
5661
entities.extend(
5762
[
5863
PlugwiseUSBBinarySensor(node_duc, entity_description)
@@ -71,7 +76,7 @@ async def async_add_binary_sensor(node_event: NodeEvent, mac: str) -> None:
7176
api_stick.subscribe_to_node_events(
7277
async_add_binary_sensor,
7378
(NodeEvent.LOADED,),
74-
)
79+
)
7580
)
7681

7782
# load current nodes
@@ -97,11 +102,11 @@ def _handle_coordinator_update(self) -> None:
97102
if self.coordinator.data[self.entity_description.node_feature] is None:
98103
_LOGGER.info(
99104
"No binary sensor data for %s",
100-
str(self.entity_description.node_feature)
105+
str(self.entity_description.node_feature),
101106
)
102107
return
103108
self._attr_is_on = getattr(
104109
self.coordinator.data[self.entity_description.node_feature],
105-
self.entity_description.key
110+
self.entity_description.key,
106111
)
107112
self.async_write_ha_state()

custom_components/plugwise_usb/config_flow.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Config flow for Plugwise USB integration."""
2+
23
from __future__ import annotations
34

45
from typing import Any
@@ -21,12 +22,13 @@
2122
def plugwise_stick_entries(hass):
2223
"""Return existing connections for Plugwise USB-stick domain."""
2324

24-
return [entry.data.get(CONF_USB_PATH) for entry in hass.config_entries.async_entries(DOMAIN)]
25+
return [
26+
entry.data.get(CONF_USB_PATH)
27+
for entry in hass.config_entries.async_entries(DOMAIN)
28+
]
2529

2630

27-
async def validate_usb_connection(
28-
self, device_path=None
29-
) -> tuple[dict[str, str], str]:
31+
async def validate_usb_connection(self, device_path=None) -> tuple[dict[str, str], str]:
3032
"""Test if device_path is a real Plugwise USB-Stick."""
3133
errors = {}
3234

@@ -111,9 +113,7 @@ async def async_step_manual_path(
111113
return self.async_show_form(
112114
step_id="manual_path",
113115
data_schema=vol.Schema(
114-
{
115-
vol.Required(CONF_USB_PATH, default="/dev/ttyUSB0"): str
116-
}
116+
{vol.Required(CONF_USB_PATH, default="/dev/ttyUSB0"): str}
117117
),
118118
errors=errors,
119119
)

custom_components/plugwise_usb/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Constants for Plugwise USB component."""
2+
23
import logging
34
from typing import Final
45

custom_components/plugwise_usb/coordinator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""DataUpdateCoordinator for Plugwise USB-Stick."""
2+
23
from collections import Counter
34
from datetime import timedelta
45
import logging
@@ -38,7 +39,9 @@ def __init__(
3839
always_update=True,
3940
)
4041
else:
41-
_LOGGER.debug("Create DUC for %s with update interval %s", node.mac, update_interval)
42+
_LOGGER.debug(
43+
"Create DUC for %s with update interval %s", node.mac, update_interval
44+
)
4245
super().__init__(
4346
hass,
4447
_LOGGER,

custom_components/plugwise_usb/entity.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Plugwise USB stick base entity."""
2+
23
from __future__ import annotations
34

45
from collections.abc import Callable
@@ -54,7 +55,8 @@ async def async_added_to_hass(self):
5455
"""Subscribe for push updates."""
5556
await super().async_added_to_hass()
5657
push_features = tuple(
57-
push_feature for push_feature in PUSHING_FEATURES
58+
push_feature
59+
for push_feature in PUSHING_FEATURES
5860
if push_feature in self._node_info.features
5961
)
6062
# Subscribe to events
@@ -65,9 +67,14 @@ async def async_added_to_hass(self):
6567
)
6668

6769
async def async_push_event(self, feature: NodeFeature, state: Any) -> None:
68-
""""Update data on pushed event."""
70+
"""Update data on pushed event."""
6971
if self.node_duc is None:
70-
_LOGGER.warning("Unable to push event=%s, state=%s, mac=%s", feature, state, self._node_info.mac)
72+
_LOGGER.warning(
73+
"Unable to push event=%s, state=%s, mac=%s",
74+
feature,
75+
state,
76+
self._node_info.mac,
77+
)
7178
self.node_duc.async_set_updated_data(
7279
{
7380
feature: state,

custom_components/plugwise_usb/sensor.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Plugwise USN Sensor component for Home Assistant."""
2+
23
from __future__ import annotations
34

45
from dataclasses import dataclass
@@ -35,7 +36,9 @@
3536

3637

3738
@dataclass(kw_only=True)
38-
class PlugwiseSensorEntityDescription(PlugwiseUSBEntityDescription, SensorEntityDescription):
39+
class PlugwiseSensorEntityDescription(
40+
PlugwiseUSBEntityDescription, SensorEntityDescription
41+
):
3942
"""Describes Plugwise sensor entity."""
4043

4144

@@ -160,7 +163,7 @@ async def async_add_sensor(node_event: NodeEvent, mac: str) -> None:
160163
api_stick.subscribe_to_node_events(
161164
async_add_sensor,
162165
(NodeEvent.LOADED,),
163-
)
166+
)
164167
)
165168

166169
# load current nodes
@@ -192,16 +195,12 @@ def _handle_coordinator_update(self) -> None:
192195
)
193196
return
194197
self._attr_native_value = getattr(
195-
self.coordinator.data[
196-
self.entity_description.node_feature
197-
],
198-
self.entity_description.key
198+
self.coordinator.data[self.entity_description.node_feature],
199+
self.entity_description.key,
199200
)
200201
if self.entity_description.node_feature == NodeFeature.ENERGY:
201202
self._attr_last_reset = getattr(
202-
self.coordinator.data[
203-
self.entity_description.node_feature
204-
],
205-
f"{self.entity_description.key}_reset"
203+
self.coordinator.data[self.entity_description.node_feature],
204+
f"{self.entity_description.key}_reset",
206205
)
207206
self.async_write_ha_state()

custom_components/plugwise_usb/switch.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Plugwise USB Switch component for HomeAssistant."""
2+
23
from __future__ import annotations
34

45
from dataclasses import dataclass
@@ -26,7 +27,9 @@
2627

2728

2829
@dataclass(kw_only=True)
29-
class PlugwiseSwitchEntityDescription(PlugwiseUSBEntityDescription, SwitchEntityDescription):
30+
class PlugwiseSwitchEntityDescription(
31+
PlugwiseUSBEntityDescription, SwitchEntityDescription
32+
):
3033
"""Describes Plugwise switch entity."""
3134

3235
async_switch_fn: str = ""
@@ -83,7 +86,7 @@ async def async_add_switch(node_event: NodeEvent, mac: str) -> None:
8386
api_stick.subscribe_to_node_events(
8487
async_add_switch,
8588
(NodeEvent.LOADED,),
86-
)
89+
)
8790
)
8891

8992
# load any current nodes
@@ -119,13 +122,12 @@ def _handle_coordinator_update(self) -> None:
119122
"""Handle updated data from the coordinator."""
120123
if self.coordinator.data[self.entity_description.node_feature] is None:
121124
_LOGGER.info(
122-
"No switch data for %s",
123-
str(self.entity_description.node_feature)
125+
"No switch data for %s", str(self.entity_description.node_feature)
124126
)
125127
return
126128
self._attr_is_on = getattr(
127129
self.coordinator.data[self.entity_description.node_feature],
128-
self.entity_description.key
130+
self.entity_description.key,
129131
)
130132
self.async_write_ha_state()
131133

0 commit comments

Comments
 (0)