From c70f06be480e20c79d982ec4b309e9d9d3a8ed74 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 13 Nov 2021 12:22:07 +0100 Subject: [PATCH] Upgrade twentemilieu to 0.4.2 (#59599) --- .../components/twentemilieu/config_flow.py | 2 +- .../components/twentemilieu/manifest.json | 2 +- .../components/twentemilieu/sensor.py | 66 ++++++++++++------- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 5 files changed, 45 insertions(+), 29 deletions(-) diff --git a/homeassistant/components/twentemilieu/config_flow.py b/homeassistant/components/twentemilieu/config_flow.py index 870ce591788..6a70fbbdcbe 100644 --- a/homeassistant/components/twentemilieu/config_flow.py +++ b/homeassistant/components/twentemilieu/config_flow.py @@ -53,7 +53,7 @@ class TwenteMilieuFlowHandler(ConfigFlow, domain=DOMAIN): twentemilieu = TwenteMilieu( post_code=user_input[CONF_POST_CODE], house_number=user_input[CONF_HOUSE_NUMBER], - house_letter=user_input.get(CONF_HOUSE_LETTER), + house_letter=user_input.get(CONF_HOUSE_LETTER, ""), session=session, ) diff --git a/homeassistant/components/twentemilieu/manifest.json b/homeassistant/components/twentemilieu/manifest.json index a56154cba71..48aa908356a 100644 --- a/homeassistant/components/twentemilieu/manifest.json +++ b/homeassistant/components/twentemilieu/manifest.json @@ -3,7 +3,7 @@ "name": "Twente Milieu", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/twentemilieu", - "requirements": ["twentemilieu==0.3.0"], + "requirements": ["twentemilieu==0.4.2"], "codeowners": ["@frenck"], "iot_class": "cloud_polling" } diff --git a/homeassistant/components/twentemilieu/sensor.py b/homeassistant/components/twentemilieu/sensor.py index 4b76f3f475b..d13ae3a7165 100644 --- a/homeassistant/components/twentemilieu/sensor.py +++ b/homeassistant/components/twentemilieu/sensor.py @@ -1,14 +1,9 @@ """Support for Twente Milieu sensors.""" from __future__ import annotations -from twentemilieu import ( - WASTE_TYPE_NON_RECYCLABLE, - WASTE_TYPE_ORGANIC, - WASTE_TYPE_PAPER, - WASTE_TYPE_PLASTIC, - TwenteMilieu, - TwenteMilieuConnectionError, -) +from dataclasses import dataclass + +from twentemilieu import TwenteMilieu, TwenteMilieuConnectionError, WasteType from homeassistant.components.sensor import SensorEntity, SensorEntityDescription from homeassistant.config_entries import ConfigEntry @@ -23,28 +18,47 @@ from .const import DATA_UPDATE, DOMAIN PARALLEL_UPDATES = 1 -SENSORS: tuple[SensorEntityDescription, ...] = ( - SensorEntityDescription( - key=WASTE_TYPE_NON_RECYCLABLE, - name=f"{WASTE_TYPE_NON_RECYCLABLE} Waste Pickup", + +@dataclass +class TwenteMilieuSensorDescriptionMixin: + """Define an entity description mixin.""" + + waste_type: WasteType + + +@dataclass +class TwenteMilieuSensorDescription( + SensorEntityDescription, TwenteMilieuSensorDescriptionMixin +): + """Describe an Ambient PWS binary sensor.""" + + +SENSORS: tuple[TwenteMilieuSensorDescription, ...] = ( + TwenteMilieuSensorDescription( + key="Non-recyclable", + waste_type=WasteType.NON_RECYCLABLE, + name="Non-recyclable Waste Pickup", icon="mdi:delete-empty", device_class=DEVICE_CLASS_DATE, ), - SensorEntityDescription( - key=WASTE_TYPE_ORGANIC, - name=f"{WASTE_TYPE_ORGANIC} Waste Pickup", + TwenteMilieuSensorDescription( + key="Organic", + waste_type=WasteType.ORGANIC, + name="Organic Waste Pickup", icon="mdi:delete-empty", device_class=DEVICE_CLASS_DATE, ), - SensorEntityDescription( - key=WASTE_TYPE_PAPER, - name=f"{WASTE_TYPE_PAPER} Waste Pickup", + TwenteMilieuSensorDescription( + key="Paper", + waste_type=WasteType.PAPER, + name="Paper Waste Pickup", icon="mdi:delete-empty", device_class=DEVICE_CLASS_DATE, ), - SensorEntityDescription( - key=WASTE_TYPE_PLASTIC, - name=f"{WASTE_TYPE_PLASTIC} Waste Pickup", + TwenteMilieuSensorDescription( + key="Plastic", + waste_type=WasteType.PACKAGES, + name="Packages Waste Pickup", icon="mdi:delete-empty", device_class=DEVICE_CLASS_DATE, ), @@ -76,13 +90,14 @@ async def async_setup_entry( class TwenteMilieuSensor(SensorEntity): """Defines a Twente Milieu sensor.""" + entity_description: TwenteMilieuSensorDescription _attr_should_poll = False def __init__( self, twentemilieu: TwenteMilieu, unique_id: str, - description: SensorEntityDescription, + description: TwenteMilieuSensorDescription, ) -> None: """Initialize the Twente Milieu entity.""" self.entity_description = description @@ -104,6 +119,7 @@ class TwenteMilieuSensor(SensorEntity): async def async_update(self) -> None: """Update Twente Milieu entity.""" - next_pickup = await self._twentemilieu.next_pickup(self.entity_description.key) - if next_pickup is not None: - self._attr_native_value = next_pickup.date().isoformat() + pickups = await self._twentemilieu.update() + self._attr_native_value = None + if pickup := pickups.get(self.entity_description.waste_type): + self._attr_native_value = pickup.isoformat() diff --git a/requirements_all.txt b/requirements_all.txt index 02c0f9fa688..66b15e3d266 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2332,7 +2332,7 @@ transmissionrpc==0.11 tuya-iot-py-sdk==0.6.3 # homeassistant.components.twentemilieu -twentemilieu==0.3.0 +twentemilieu==0.4.2 # homeassistant.components.twilio twilio==6.32.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 5b89e207593..6b6468e9591 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1354,7 +1354,7 @@ transmissionrpc==0.11 tuya-iot-py-sdk==0.6.3 # homeassistant.components.twentemilieu -twentemilieu==0.3.0 +twentemilieu==0.4.2 # homeassistant.components.twilio twilio==6.32.0