Rename state to value_fn - picnic sensor (#56889)

pull/56897/head
Marc Mueller 2021-10-01 15:21:43 +02:00 committed by GitHub
parent dc40de6b62
commit 954bd49849
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 15 deletions

View File

@ -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,
),
)

View File

@ -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: