mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
TotalConnect use entry.runtime_data (#133756)
* use entry.runtime_data * type the entry * update quality scale * recommended fixes * Update homeassistant/components/totalconnect/alarm_control_panel.py * Update homeassistant/components/totalconnect/binary_sensor.py * Update homeassistant/components/totalconnect/button.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
c2a9b0ff52
commit
d322398d06
@ -8,13 +8,17 @@ from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||
|
||||
from .const import AUTO_BYPASS, CONF_USERCODES, DOMAIN
|
||||
from .const import AUTO_BYPASS, CONF_USERCODES
|
||||
from .coordinator import TotalConnectDataUpdateCoordinator
|
||||
|
||||
PLATFORMS = [Platform.ALARM_CONTROL_PANEL, Platform.BINARY_SENSOR, Platform.BUTTON]
|
||||
|
||||
type TotalConnectConfigEntry = ConfigEntry[TotalConnectDataUpdateCoordinator]
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: TotalConnectConfigEntry
|
||||
) -> bool:
|
||||
"""Set up upon config entry in user interface."""
|
||||
conf = entry.data
|
||||
username = conf[CONF_USERNAME]
|
||||
@ -40,8 +44,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
coordinator = TotalConnectDataUpdateCoordinator(hass, client)
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
hass.data[DOMAIN][entry.entry_id] = coordinator
|
||||
entry.runtime_data = coordinator
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
|
||||
entry.async_on_unload(entry.add_update_listener(update_listener))
|
||||
@ -49,18 +52,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(
|
||||
hass: HomeAssistant, entry: TotalConnectConfigEntry
|
||||
) -> bool:
|
||||
"""Unload a config entry."""
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
if unload_ok:
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
|
||||
return unload_ok
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
|
||||
async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
async def update_listener(hass: HomeAssistant, entry: TotalConnectConfigEntry) -> None:
|
||||
"""Update listener."""
|
||||
bypass = entry.options.get(AUTO_BYPASS, False)
|
||||
client = hass.data[DOMAIN][entry.entry_id].client
|
||||
client = entry.runtime_data.client
|
||||
for location_id in client.locations:
|
||||
client.locations[location_id].auto_bypass_low_battery = bypass
|
||||
|
@ -30,7 +30,7 @@ async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up TotalConnect alarm panels based on a config entry."""
|
||||
coordinator: TotalConnectDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
coordinator = entry.runtime_data
|
||||
code_required = entry.options.get(CODE_REQUIRED, False)
|
||||
|
||||
async_add_entities(
|
||||
|
@ -17,7 +17,6 @@ from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import TotalConnectDataUpdateCoordinator
|
||||
from .entity import TotalConnectLocationEntity, TotalConnectZoneEntity
|
||||
|
||||
@ -125,7 +124,7 @@ async def async_setup_entry(
|
||||
"""Set up TotalConnect device sensors based on a config entry."""
|
||||
sensors: list = []
|
||||
|
||||
coordinator: TotalConnectDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
client_locations = coordinator.client.locations
|
||||
|
||||
|
@ -12,7 +12,6 @@ from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import TotalConnectDataUpdateCoordinator
|
||||
from .entity import TotalConnectLocationEntity, TotalConnectZoneEntity
|
||||
|
||||
@ -43,7 +42,7 @@ async def async_setup_entry(
|
||||
) -> None:
|
||||
"""Set up TotalConnect buttons based on a config entry."""
|
||||
buttons: list = []
|
||||
coordinator: TotalConnectDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
for location_id, location in coordinator.client.locations.items():
|
||||
buttons.extend(
|
||||
|
@ -8,8 +8,6 @@ from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
TO_REDACT = [
|
||||
"username",
|
||||
"Password",
|
||||
@ -27,7 +25,7 @@ async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
client = hass.data[DOMAIN][config_entry.entry_id].client
|
||||
client = config_entry.runtime_data.client
|
||||
|
||||
data: dict[str, Any] = {}
|
||||
data["client"] = {
|
||||
|
@ -4,7 +4,7 @@ rules:
|
||||
test-before-configure: done
|
||||
unique-config-entry: done
|
||||
config-flow-test-coverage: todo
|
||||
runtime-data: todo
|
||||
runtime-data: done
|
||||
test-before-setup: todo
|
||||
appropriate-polling: done
|
||||
entity-unique-id: done
|
||||
|
Loading…
x
Reference in New Issue
Block a user