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

View File

@ -1,4 +1,5 @@
"""Config flow for Tedee integration.""" """Config flow for Tedee integration."""
from collections.abc import Mapping from collections.abc import Mapping
from typing import Any from typing import Any
@ -83,14 +84,24 @@ class TedeeConfigFlow(ConfigFlow, domain=DOMAIN):
self.reauth_entry = self.hass.config_entries.async_get_entry( self.reauth_entry = self.hass.config_entries.async_get_entry(
self.context["entry_id"] self.context["entry_id"]
) )
return self.async_show_form( return await self.async_step_reauth_confirm()
step_id="user",
data_schema=vol.Schema( async def async_step_reauth_confirm(
{ self, user_input: dict[str, Any] | None = None
vol.Required( ) -> FlowResult:
CONF_LOCAL_ACCESS_TOKEN, """Dialog that informs the user that reauth is required."""
default=entry_data[CONF_LOCAL_ACCESS_TOKEN], assert self.reauth_entry
): str,
} 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.""" """Tedee sensor entities."""
from collections.abc import Callable from collections.abc import Callable
from dataclasses import dataclass from dataclasses import dataclass
@ -11,7 +12,7 @@ from homeassistant.components.sensor import (
SensorStateClass, SensorStateClass,
) )
from homeassistant.config_entries import ConfigEntry 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.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -33,15 +34,17 @@ ENTITIES: tuple[TedeeSensorEntityDescription, ...] = (
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
value_fn=lambda lock: lock.battery_level, value_fn=lambda lock: lock.battery_level,
entity_category=EntityCategory.DIAGNOSTIC,
), ),
TedeeSensorEntityDescription( TedeeSensorEntityDescription(
key="pullspring_duration", key="pullspring_duration",
translation_key="pullspring_duration", translation_key="pullspring_duration",
device_class=SensorDeviceClass.DURATION, device_class=SensorDeviceClass.DURATION,
native_unit_of_measurement=UnitOfTime.SECONDS, native_unit_of_measurement=UnitOfTime.SECONDS,
state_class=SensorStateClass.TOTAL, state_class=SensorStateClass.MEASUREMENT,
icon="mdi:timer-lock-open", icon="mdi:timer-lock-open",
value_fn=lambda lock: lock.duration_pullspring, 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.""" """Set up the Tedee sensor entity."""
coordinator = hass.data[DOMAIN][entry.entry_id] coordinator = hass.data[DOMAIN][entry.entry_id]
for entity_description in ENTITIES: async_add_entities(
async_add_entities( TedeeSensorEntity(lock, coordinator, entity_description)
[ for lock in coordinator.data.values()
TedeeSensorEntity(lock, coordinator, entity_description) for entity_description in ENTITIES
for lock in coordinator.data.values() )
]
)
def _async_add_new_lock(lock_id: int) -> None: def _async_add_new_lock(lock_id: int) -> None:
lock = coordinator.data[lock_id] lock = coordinator.data[lock_id]
async_add_entities( async_add_entities(
[ TedeeSensorEntity(lock, coordinator, entity_description)
TedeeSensorEntity(lock, coordinator, entity_description) for entity_description in ENTITIES
for entity_description in ENTITIES
]
) )
coordinator.new_lock_callbacks.append(_async_add_new_lock) coordinator.new_lock_callbacks.append(_async_add_new_lock)

View File

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