Skip to content

Commit

Permalink
Merge pull request #29 from jaraco/bugfix/ha-121300-occupancy
Browse files Browse the repository at this point in the history
Restore is_on behavior for specialized BinarySensor subclasses
  • Loading branch information
jaraco authored Jul 7, 2024
2 parents 595f714 + 77986d3 commit 7201d9f
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 3 deletions.
6 changes: 3 additions & 3 deletions jaraco/abode/devices/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def is_on(self):
Assume offline or open (worst case).
"""
if self.type == 'Occupancy':
return self.status not in STATUS.ONLINE
return self.status not in (
STATUS.OFF,
STATUS.OFFLINE,
Expand Down Expand Up @@ -43,9 +45,7 @@ class Motion(BinarySensor):


class Occupancy(BinarySensor):
@property
def is_on(self):
return self.status not in STATUS.ONLINE
pass


class Door(BinarySensor):
Expand Down
1 change: 1 addition & 0 deletions newsfragments/+890794d5.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Restored specialized 'is_on' behavior to base BinarySensor for home-assistant/core#121300.
87 changes: 87 additions & 0 deletions tests/mock/devices/occupancy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"""Mock Abode Occupancy Device."""

import jaraco.abode.devices.status as STATUS

DEVICE_ID = 'RF:00000001'


def device(
devid=DEVICE_ID,
has_motion=False,
low_battery=False,
no_response=False,
out_of_order=False,
tampered=False,
uuid='87a31f855e684b1ab3b87e2d13e72465',
):
"""Occupancy sensor mock device."""

status = [STATUS.ONLINE, "Motion Detected!"][has_motion]
statuses = dict(motion=str(int(has_motion)))
return dict(
id=devid,
type_tag='device_type.povs',
type='Occupancy',
name='Vault motion',
area='1',
zone='6',
sort_order='',
is_window='',
bypass='0',
schar_24hr='0',
sresp_24hr="5",
sresp_mode_0='0',
sresp_entry_0='0',
sresp_exit_0='0',
group_name="Motion",
group_id="1156954",
default_group_id="1",
sort_id="1",
sresp_mode_1='5',
sresp_entry_1='4',
sresp_exit_1='0',
sresp_mode_2='0',
sresp_entry_2='0',
sresp_exit_2='0',
sresp_mode_3='0',
sresp_entry_3='0',
sresp_exit_3='0',
sresp_mode_4='0',
sresp_entry_4='0',
sresp_exit_4='0',
version='0001',
origin='abode',
has_subscription=None,
onboard="0",
s2_grnt_keys="",
s2_dsk="",
s2_propty="",
s2_keys_valid="",
zwave_secure_protocol="",
control_url='',
deep_link=None,
status_color='#5cb85c',
faults={
'low_battery': int(low_battery),
'tempered': int(tampered),
'supervision': 0,
'out_of_order': int(out_of_order),
'no_response': int(no_response),
'jammed': 0,
'zwave_fault': 0,
},
status=status,
status_display=status,
statuses=statuses,
status_ex='',
actions=[],
status_icons=[],
icon='assets/icons/occupancy-sensor.svg',
sresp_trigger="0",
sresp_restore="0",
occupancy_timer="30",
sensitivity="4",
model="L1",
is_motion_sensor=False,
uuid=uuid,
)
7 changes: 7 additions & 0 deletions tests/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from .mock.devices import door_contact as DOOR_CONTACT
from .mock.devices import glass as GLASS
from .mock.devices import keypad as KEYPAD
from .mock.devices import occupancy as OCCUPANCY
from .mock.devices import remote_controller as REMOTE_CONTROLLER
from .mock.devices import siren as SIREN
from .mock.devices import status_display as STATUS_DISPLAY
Expand Down Expand Up @@ -50,6 +51,7 @@ def test_binary_sensor_properties(self, m):
low_battery=False,
no_response=False,
),
OCCUPANCY.device(),
REMOTE_CONTROLLER.device(
devid=REMOTE_CONTROLLER.DEVICE_ID,
status=STATUS.OFFLINE,
Expand Down Expand Up @@ -107,6 +109,11 @@ def test_binary_sensor_properties(self, m):
low_battery=True,
no_response=True,
),
OCCUPANCY.device(
has_motion=True,
low_battery=True,
no_response=True,
),
REMOTE_CONTROLLER.device(
devid=REMOTE_CONTROLLER.DEVICE_ID,
status=STATUS.ONLINE,
Expand Down

0 comments on commit 7201d9f

Please sign in to comment.