Add late PR changes to tedee (#109858)

requested changes
This commit is contained in:
Josef Zweck 2024-02-07 08:53:19 +01:00 committed by GitHub
parent 5521a39866
commit 2fc56ff4e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 46 additions and 39 deletions

View File

@ -1,4 +1,5 @@
"""Tedee sensor entities."""
from collections.abc import Callable
from dataclasses import dataclass
@ -58,21 +59,17 @@ async def async_setup_entry(
"""Set up the Tedee sensor entity."""
coordinator = hass.data[DOMAIN][entry.entry_id]
for entity_description in ENTITIES:
async_add_entities(
[
TedeeBinarySensorEntity(lock, coordinator, entity_description)
for lock in coordinator.data.values()
]
)
async_add_entities(
TedeeBinarySensorEntity(lock, coordinator, entity_description)
for lock in coordinator.data.values()
for entity_description in ENTITIES
)
def _async_add_new_lock(lock_id: int) -> None:
lock = coordinator.data[lock_id]
async_add_entities(
[
TedeeBinarySensorEntity(lock, coordinator, entity_description)
for entity_description in ENTITIES
]
TedeeBinarySensorEntity(lock, coordinator, entity_description)
for entity_description in ENTITIES
)
coordinator.new_lock_callbacks.append(_async_add_new_lock)

View File

@ -1,4 +1,5 @@
"""Config flow for Tedee integration."""
from collections.abc import Mapping
from typing import Any
@ -83,14 +84,24 @@ class TedeeConfigFlow(ConfigFlow, domain=DOMAIN):
self.reauth_entry = self.hass.config_entries.async_get_entry(
self.context["entry_id"]
)
return self.async_show_form(
step_id="user",
data_schema=vol.Schema(
{
vol.Required(
CONF_LOCAL_ACCESS_TOKEN,
default=entry_data[CONF_LOCAL_ACCESS_TOKEN],
): str,
}
),
)
return await self.async_step_reauth_confirm()
async def async_step_reauth_confirm(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Dialog that informs the user that reauth is required."""
assert self.reauth_entry
if not user_input:
return self.async_show_form(
step_id="reauth_confirm",
data_schema=vol.Schema(
{
vol.Required(
CONF_LOCAL_ACCESS_TOKEN,
default=self.reauth_entry.data[CONF_LOCAL_ACCESS_TOKEN],
): str,
}
),
)
return await self.async_step_user(user_input)

View File

@ -1,4 +1,5 @@
"""Tedee sensor entities."""
from collections.abc import Callable
from dataclasses import dataclass
@ -11,7 +12,7 @@ from homeassistant.components.sensor import (
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import PERCENTAGE, UnitOfTime
from homeassistant.const import PERCENTAGE, EntityCategory, UnitOfTime
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -33,15 +34,17 @@ ENTITIES: tuple[TedeeSensorEntityDescription, ...] = (
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
value_fn=lambda lock: lock.battery_level,
entity_category=EntityCategory.DIAGNOSTIC,
),
TedeeSensorEntityDescription(
key="pullspring_duration",
translation_key="pullspring_duration",
device_class=SensorDeviceClass.DURATION,
native_unit_of_measurement=UnitOfTime.SECONDS,
state_class=SensorStateClass.TOTAL,
state_class=SensorStateClass.MEASUREMENT,
icon="mdi:timer-lock-open",
value_fn=lambda lock: lock.duration_pullspring,
entity_category=EntityCategory.DIAGNOSTIC,
),
)
@ -54,21 +57,17 @@ async def async_setup_entry(
"""Set up the Tedee sensor entity."""
coordinator = hass.data[DOMAIN][entry.entry_id]
for entity_description in ENTITIES:
async_add_entities(
[
TedeeSensorEntity(lock, coordinator, entity_description)
for lock in coordinator.data.values()
]
)
async_add_entities(
TedeeSensorEntity(lock, coordinator, entity_description)
for lock in coordinator.data.values()
for entity_description in ENTITIES
)
def _async_add_new_lock(lock_id: int) -> None:
lock = coordinator.data[lock_id]
async_add_entities(
[
TedeeSensorEntity(lock, coordinator, entity_description)
for entity_description in ENTITIES
]
TedeeSensorEntity(lock, coordinator, entity_description)
for entity_description in ENTITIES
)
coordinator.new_lock_callbacks.append(_async_add_new_lock)

View File

@ -12,7 +12,7 @@
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.lock_1a2b_battery',
'has_entity_name': True,
'hidden_by': None,
@ -38,14 +38,14 @@
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.TOTAL: 'total'>,
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.lock_1a2b_pullspring_duration',
'has_entity_name': True,
'hidden_by': None,
@ -86,7 +86,7 @@
'device_class': 'duration',
'friendly_name': 'Lock-1A2B Pullspring duration',
'icon': 'mdi:timer-lock-open',
'state_class': <SensorStateClass.TOTAL: 'total'>,
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfTime.SECONDS: 's'>,
}),
'context': <ANY>,