Skip to content

Commit 884327b

Browse files
committed
Clean up models.py
1 parent 55424cf commit 884327b

File tree

5 files changed

+12
-43
lines changed

5 files changed

+12
-43
lines changed

custom_components/plugwise_usb/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def __init__(
204204
}
205205
self._attr_name = f"{entity_description.name} ({node.mac[-5:]})"
206206
# Github issue #265
207-
self._attr_should_poll = entity_description.should_poll # type: ignore[attr-defined]
207+
self._attr_should_poll = entity_description.should_poll
208208
# /Github issue #265
209209
self._attr_unique_id = f"{node.mac}-{entity_description.key}"
210210
self._node = node

custom_components/plugwise_usb/binary_sensor.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ async def async_add_binary_sensors(mac: str):
5353
[
5454
USBBinarySensor(api_stick.devices[mac], description)
5555
for description in PW_BINARY_SENSOR_TYPES
56-
if description.plugwise_api == STICK
57-
and description.key in api_stick.devices[mac].features
56+
if description.key in api_stick.devices[mac].features
5857
]
5958
)
6059
if entities:
@@ -103,7 +102,7 @@ def __init__(
103102
def is_on(self) -> bool:
104103
"""Return true if the binary_sensor is on."""
105104
# Github issue #265
106-
return getattr(self._node, self.entity_description.state_request_method) # type: ignore[attr-defined]
105+
return getattr(self._node, self.entity_description.state_request_method)
107106

108107
def _service_scan_config(self, **kwargs):
109108
"""Service call to configure motion sensor of Scan device."""

custom_components/plugwise_usb/models.py

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,64 +22,47 @@
2222
)
2323
from homeassistant.helpers.entity import EntityDescription
2424

25-
from .const import STICK, USB_MOTION_ID, USB_RELAY_ID
25+
from .const import USB_MOTION_ID, USB_RELAY_ID
2626

2727

2828
@dataclass
29-
class PlugwiseRequiredKeysMixin:
30-
"""Mixin for required keys."""
31-
32-
plugwise_api: str
33-
34-
35-
@dataclass
36-
class PlugwiseEntityDescription(EntityDescription, PlugwiseRequiredKeysMixin):
29+
class PlugwiseEntityDescription(EntityDescription):
3730
"""Generic Plugwise entity description."""
3831

32+
should_poll: bool = False
33+
state_request_method: str = "dummy"
34+
3935

4036
@dataclass
4137
class PlugwiseSensorEntityDescription(
4238
SensorEntityDescription, PlugwiseEntityDescription
4339
):
4440
"""Describes Plugwise sensor entity."""
4541

46-
should_poll: bool = False
47-
state_class: str | None = SensorStateClass.MEASUREMENT
48-
state_request_method: str | None = None
49-
5042

5143
@dataclass
5244
class PlugwiseSwitchEntityDescription(
5345
SwitchEntityDescription, PlugwiseEntityDescription
5446
):
5547
"""Describes Plugwise switch entity."""
5648

57-
should_poll: bool = False
58-
state_request_method: str | None = None
59-
6049

6150
@dataclass
6251
class PlugwiseBinarySensorEntityDescription(
6352
BinarySensorEntityDescription, PlugwiseEntityDescription
6453
):
6554
"""Describes Plugwise binary sensor entity."""
6655

67-
icon_off: str | None = None
68-
should_poll: bool = False
69-
state_request_method: str | None = None
70-
7156

7257
PW_SENSOR_TYPES: tuple[PlugwiseSensorEntityDescription, ...] = (
7358
PlugwiseSensorEntityDescription(
74-
plugwise_api=STICK,
7559
key="power_1s",
7660
name="Power usage",
7761
device_class=SensorDeviceClass.POWER,
7862
native_unit_of_measurement=UnitOfPower.WATT,
7963
state_request_method="current_power_usage",
8064
),
8165
PlugwiseSensorEntityDescription(
82-
plugwise_api=STICK,
8366
key="energy_consumption_today",
8467
name="Energy consumption today",
8568
device_class=SensorDeviceClass.ENERGY,
@@ -88,7 +71,6 @@ class PlugwiseBinarySensorEntityDescription(
8871
state_request_method="energy_consumption_today",
8972
),
9073
PlugwiseSensorEntityDescription(
91-
plugwise_api=STICK,
9274
key="ping",
9375
name="Ping roundtrip",
9476
icon="mdi:speedometer",
@@ -98,7 +80,6 @@ class PlugwiseBinarySensorEntityDescription(
9880
entity_category=EntityCategory.DIAGNOSTIC,
9981
),
10082
PlugwiseSensorEntityDescription(
101-
plugwise_api=STICK,
10283
key="power_8s",
10384
name="Power usage 8 seconds",
10485
device_class=SensorDeviceClass.POWER,
@@ -107,7 +88,6 @@ class PlugwiseBinarySensorEntityDescription(
10788
entity_registry_enabled_default=False,
10889
),
10990
PlugwiseSensorEntityDescription(
110-
plugwise_api=STICK,
11191
key="RSSI_in",
11292
name="Inbound RSSI",
11393
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
@@ -117,7 +97,6 @@ class PlugwiseBinarySensorEntityDescription(
11797
entity_category=EntityCategory.DIAGNOSTIC,
11898
),
11999
PlugwiseSensorEntityDescription(
120-
plugwise_api=STICK,
121100
key="RSSI_out",
122101
name="Outbound RSSI",
123102
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
@@ -127,7 +106,6 @@ class PlugwiseBinarySensorEntityDescription(
127106
entity_category=EntityCategory.DIAGNOSTIC,
128107
),
129108
PlugwiseSensorEntityDescription(
130-
plugwise_api=STICK,
131109
key="power_con_cur_hour",
132110
name="Power consumption current hour",
133111
icon="mdi:lightning-bolt",
@@ -136,7 +114,6 @@ class PlugwiseBinarySensorEntityDescription(
136114
entity_registry_enabled_default=False,
137115
),
138116
PlugwiseSensorEntityDescription(
139-
plugwise_api=STICK,
140117
key="power_prod_cur_hour",
141118
name="Power production current hour",
142119
icon="mdi:lightning-bolt",
@@ -145,7 +122,6 @@ class PlugwiseBinarySensorEntityDescription(
145122
entity_registry_enabled_default=False,
146123
),
147124
PlugwiseSensorEntityDescription(
148-
plugwise_api=STICK,
149125
key="power_con_today",
150126
name="Power consumption today",
151127
icon="mdi:lightning-bolt",
@@ -154,7 +130,6 @@ class PlugwiseBinarySensorEntityDescription(
154130
entity_registry_enabled_default=False,
155131
),
156132
PlugwiseSensorEntityDescription(
157-
plugwise_api=STICK,
158133
key="power_con_prev_hour",
159134
name="Power consumption previous hour",
160135
icon="mdi:lightning-bolt",
@@ -164,7 +139,6 @@ class PlugwiseBinarySensorEntityDescription(
164139
entity_registry_enabled_default=False,
165140
),
166141
PlugwiseSensorEntityDescription(
167-
plugwise_api=STICK,
168142
key="power_con_yesterday",
169143
name="Power consumption yesterday",
170144
icon="mdi:lightning-bolt",
@@ -177,7 +151,6 @@ class PlugwiseBinarySensorEntityDescription(
177151

178152
PW_SWITCH_TYPES: tuple[PlugwiseSwitchEntityDescription, ...] = (
179153
PlugwiseSwitchEntityDescription(
180-
plugwise_api=STICK,
181154
key=USB_RELAY_ID,
182155
device_class=SwitchDeviceClass.OUTLET,
183156
name="Relay state",
@@ -187,7 +160,6 @@ class PlugwiseBinarySensorEntityDescription(
187160

188161
PW_BINARY_SENSOR_TYPES: tuple[PlugwiseBinarySensorEntityDescription, ...] = (
189162
PlugwiseBinarySensorEntityDescription(
190-
plugwise_api=STICK,
191163
key=USB_MOTION_ID,
192164
name="Motion",
193165
device_class=BinarySensorDeviceClass.MOTION,

custom_components/plugwise_usb/sensor.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ async def async_add_sensors(mac: str):
3030
[
3131
USBSensor(api_stick.devices[mac], description)
3232
for description in PW_SENSOR_TYPES
33-
if description.plugwise_api == STICK
34-
and description.key in api_stick.devices[mac].features
33+
if description.key in api_stick.devices[mac].features
3534
]
3635
)
3736
if entities:
@@ -62,7 +61,7 @@ def __init__(
6261
def native_value(self) -> float | None:
6362
"""Return the native value of the sensor."""
6463
# Github issue #265
65-
state_value = getattr(self._node, self.entity_description.state_request_method) # type: ignore[attr-defined]
64+
state_value = getattr(self._node, self.entity_description.state_request_method)
6665
# /Github issue #265
6766
if state_value is not None:
6867
return float(round(state_value, 3))

custom_components/plugwise_usb/switch.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ async def async_add_switches(mac: str):
2828
[
2929
USBSwitch(api_stick.devices[mac], description)
3030
for description in PW_SWITCH_TYPES
31-
if description.plugwise_api == STICK
32-
and description.key in api_stick.devices[mac].features
31+
if description.key in api_stick.devices[mac].features
3332
]
3433
)
3534
if entities:
@@ -60,7 +59,7 @@ def __init__(
6059
def is_on(self) -> bool:
6160
"""Return true if the switch is on."""
6261
# Github issue #265
63-
return getattr(self._node, self.entity_description.state_request_method) # type: ignore[attr-defined]
62+
return getattr(self._node, self.entity_description.state_request_method)
6463

6564
def turn_off(self, **kwargs):
6665
"""Instruct the switch to turn off."""

0 commit comments

Comments
 (0)