Skip to content

Commit

Permalink
Fix default device_class for binary sensor #779
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed May 3, 2022
1 parent 51e15fa commit 51ed581
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 3 additions & 3 deletions custom_components/sonoff/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ async def async_setup_entry(hass, config_entry, add_entities):
class XBinarySensor(XEntity, BinarySensorEntity):
def __init__(self, ewelink: XRegistry, device: dict):
XEntity.__init__(self, ewelink, device)
self._attr_device_class = DEVICE_CLASSES.get(
device.get("device_class")
)
device_class = device.get("device_class")
if device_class in DEVICE_CLASSES:
self._attr_device_class = DEVICE_CLASSES[device_class]


# noinspection PyAbstractClass
Expand Down
6 changes: 1 addition & 5 deletions tests/test_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,15 +553,11 @@ def test_wifi_sensor():
"switch": "off",
"type": 4
}
}, {
"devices": {
DEVICEID: {"device_class": "window"}
}
})

sensor: XBinarySensor = entities[0]
assert sensor.state == "off"
assert sensor.device_class == BinarySensorDeviceClass.WINDOW
assert sensor.device_class == BinarySensorDeviceClass.DOOR
assert sensor.available is False

sensor.ewelink.cloud.online = True
Expand Down

0 comments on commit 51ed581

Please sign in to comment.