diff --git a/custom_components/mail_and_packages/binary_sensor.py b/custom_components/mail_and_packages/binary_sensor.py index 8b2c9dc7..081f695f 100644 --- a/custom_components/mail_and_packages/binary_sensor.py +++ b/custom_components/mail_and_packages/binary_sensor.py @@ -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 diff --git a/custom_components/mail_and_packages/const.py b/custom_components/mail_and_packages/const.py index 708e8b19..de811caa 100644 --- a/custom_components/mail_and_packages/const.py +++ b/custom_components/mail_and_packages/const.py @@ -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 diff --git a/custom_components/mail_and_packages/helpers.py b/custom_components/mail_and_packages/helpers.py index 6fb8e3d9..3d7ae3de 100644 --- a/custom_components/mail_and_packages/helpers.py +++ b/custom_components/mail_and_packages/helpers.py @@ -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"][ diff --git a/tests/test_binary_sensor.py b/tests/test_binary_sensor.py index 24e4ba83..1988608e 100644 --- a/tests/test_binary_sensor.py +++ b/tests/test_binary_sensor.py @@ -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):