From 954bd49849f9f63c7bea5fb0ebbbb3593859ffa4 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 1 Oct 2021 15:21:43 +0200 Subject: [PATCH] Rename state to value_fn - picnic sensor (#56889) --- homeassistant/components/picnic/const.py | 28 +++++++++++------------ homeassistant/components/picnic/sensor.py | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/picnic/const.py b/homeassistant/components/picnic/const.py index 5aa21fd671b..228983d8189 100644 --- a/homeassistant/components/picnic/const.py +++ b/homeassistant/components/picnic/const.py @@ -42,7 +42,7 @@ class PicnicRequiredKeysMixin: """Mixin for required keys.""" data_type: Literal["cart_data", "slot_data", "last_order_data"] - state: Callable[[Any], StateType] + value_fn: Callable[[Any], StateType] @dataclass @@ -57,7 +57,7 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = ( key=SENSOR_CART_ITEMS_COUNT, icon="mdi:format-list-numbered", data_type="cart_data", - state=lambda cart: cart.get("total_count", 0), + value_fn=lambda cart: cart.get("total_count", 0), ), PicnicSensorEntityDescription( key=SENSOR_CART_TOTAL_PRICE, @@ -65,7 +65,7 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = ( icon="mdi:currency-eur", entity_registry_enabled_default=True, data_type="cart_data", - state=lambda cart: cart.get("total_price", 0) / 100, + value_fn=lambda cart: cart.get("total_price", 0) / 100, ), PicnicSensorEntityDescription( key=SENSOR_SELECTED_SLOT_START, @@ -73,7 +73,7 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = ( icon="mdi:calendar-start", entity_registry_enabled_default=True, data_type="slot_data", - state=lambda slot: slot.get("window_start"), + value_fn=lambda slot: slot.get("window_start"), ), PicnicSensorEntityDescription( key=SENSOR_SELECTED_SLOT_END, @@ -81,7 +81,7 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = ( icon="mdi:calendar-end", entity_registry_enabled_default=True, data_type="slot_data", - state=lambda slot: slot.get("window_end"), + value_fn=lambda slot: slot.get("window_end"), ), PicnicSensorEntityDescription( key=SENSOR_SELECTED_SLOT_MAX_ORDER_TIME, @@ -89,7 +89,7 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = ( icon="mdi:clock-alert-outline", entity_registry_enabled_default=True, data_type="slot_data", - state=lambda slot: slot.get("cut_off_time"), + value_fn=lambda slot: slot.get("cut_off_time"), ), PicnicSensorEntityDescription( key=SENSOR_SELECTED_SLOT_MIN_ORDER_VALUE, @@ -97,7 +97,7 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = ( icon="mdi:currency-eur", entity_registry_enabled_default=True, data_type="slot_data", - state=lambda slot: ( + value_fn=lambda slot: ( slot["minimum_order_value"] / 100 if slot.get("minimum_order_value") else None @@ -108,20 +108,20 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = ( device_class=DEVICE_CLASS_TIMESTAMP, icon="mdi:calendar-start", data_type="last_order_data", - state=lambda last_order: last_order.get("slot", {}).get("window_start"), + value_fn=lambda last_order: last_order.get("slot", {}).get("window_start"), ), PicnicSensorEntityDescription( key=SENSOR_LAST_ORDER_SLOT_END, device_class=DEVICE_CLASS_TIMESTAMP, icon="mdi:calendar-end", data_type="last_order_data", - state=lambda last_order: last_order.get("slot", {}).get("window_end"), + value_fn=lambda last_order: last_order.get("slot", {}).get("window_end"), ), PicnicSensorEntityDescription( key=SENSOR_LAST_ORDER_STATUS, icon="mdi:list-status", data_type="last_order_data", - state=lambda last_order: last_order.get("status"), + value_fn=lambda last_order: last_order.get("status"), ), PicnicSensorEntityDescription( key=SENSOR_LAST_ORDER_ETA_START, @@ -129,7 +129,7 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = ( icon="mdi:clock-start", entity_registry_enabled_default=True, data_type="last_order_data", - state=lambda last_order: last_order.get("eta", {}).get("start"), + value_fn=lambda last_order: last_order.get("eta", {}).get("start"), ), PicnicSensorEntityDescription( key=SENSOR_LAST_ORDER_ETA_END, @@ -137,7 +137,7 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = ( icon="mdi:clock-end", entity_registry_enabled_default=True, data_type="last_order_data", - state=lambda last_order: last_order.get("eta", {}).get("end"), + value_fn=lambda last_order: last_order.get("eta", {}).get("end"), ), PicnicSensorEntityDescription( key=SENSOR_LAST_ORDER_DELIVERY_TIME, @@ -145,13 +145,13 @@ SENSOR_TYPES: tuple[PicnicSensorEntityDescription, ...] = ( icon="mdi:timeline-clock", entity_registry_enabled_default=True, data_type="last_order_data", - state=lambda last_order: last_order.get("delivery_time", {}).get("start"), + value_fn=lambda last_order: last_order.get("delivery_time", {}).get("start"), ), PicnicSensorEntityDescription( key=SENSOR_LAST_ORDER_TOTAL_PRICE, native_unit_of_measurement=CURRENCY_EURO, icon="mdi:cash-marker", data_type="last_order_data", - state=lambda last_order: last_order.get("total_price", 0) / 100, + value_fn=lambda last_order: last_order.get("total_price", 0) / 100, ), ) diff --git a/homeassistant/components/picnic/sensor.py b/homeassistant/components/picnic/sensor.py index 34ad2943d8e..e0f0d943663 100644 --- a/homeassistant/components/picnic/sensor.py +++ b/homeassistant/components/picnic/sensor.py @@ -68,7 +68,7 @@ class PicnicSensor(SensorEntity, CoordinatorEntity): if self.coordinator.data is not None else {} ) - return self.entity_description.state(data_set) + return self.entity_description.value_fn(data_set) @property def available(self) -> bool: