Skip to content

Commit

Permalink
feat: add usps mail delivered binary sensor (#922)
Browse files Browse the repository at this point in the history
* feat: add usps mail delivered binary sensor

* add logic to binary_sensor

* formatting
  • Loading branch information
firstof9 authored Jun 22, 2024
1 parent 130c5c9 commit 66a146f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions custom_components/mail_and_packages/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,6 @@ def is_on(self) -> bool:
if image_hash != none_hash:
return True
return False
if self._type in self.coordinator.data.keys():
return bool(self.coordinator.data[self._type])
return False
5 changes: 5 additions & 0 deletions custom_components/mail_and_packages/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,11 @@
key="amazon_update",
device_class=BinarySensorDeviceClass.UPDATE,
),
"usps_mail_delivered": BinarySensorEntityDescription(
name="USPS Mail Delivered",
key="usps_mail_delivered",
device_class=BinarySensorDeviceClass.UPDATE,
),
}

# Name
Expand Down
3 changes: 2 additions & 1 deletion custom_components/mail_and_packages/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,8 @@ def get_count(
found.append(data[0])

if (
ATTR_PATTERN
f"{'_'.join(sensor_type.split('_')[:-1])}_tracking" in SENSOR_DATA
and ATTR_PATTERN
in SENSOR_DATA[f"{'_'.join(sensor_type.split('_')[:-1])}_tracking"].keys()
):
track = SENSOR_DATA[f"{'_'.join(sensor_type.split('_')[:-1])}_tracking"][
Expand Down
4 changes: 4 additions & 0 deletions tests/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ async def test_binary_sensor_no_updates(hass, mock_imap_no_email):
assert state
assert state.state == "off"

state = hass.states.get("binary_sensor.usps_mail_delivered")
assert state
assert state.state == "off"


# @pytest.mark.asyncio
# async def test_binary_sensor_updated(hass, mock_update_amazon_image):
Expand Down

0 comments on commit 66a146f

Please sign in to comment.