Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add usps mail delivered binary sensor #922

Merged
merged 3 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading