Initial commit: Main Gate Controller HACS integration
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
"""The Main Gate Controller integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
|
||||
from .const import CONF_NAME, DEFAULT_NAME, DOMAIN, MANUFACTURER, MODEL
|
||||
from .coordinator import MainGateController
|
||||
|
||||
PLATFORMS: list[Platform] = [Platform.BUTTON, Platform.SENSOR]
|
||||
|
||||
type MainGateConfigEntry = ConfigEntry[MainGateController]
|
||||
|
||||
|
||||
@callback
|
||||
def build_device_info(entry: ConfigEntry) -> DeviceInfo:
|
||||
"""Return the ``DeviceInfo`` shared by all entities of one gate."""
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, entry.entry_id)},
|
||||
name=entry.data.get(CONF_NAME, DEFAULT_NAME),
|
||||
manufacturer=MANUFACTURER,
|
||||
model=MODEL,
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: MainGateConfigEntry) -> bool:
|
||||
"""Set up a gate from a config entry."""
|
||||
controller = MainGateController(hass, entry)
|
||||
entry.runtime_data = controller
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
|
||||
async def _async_on_options_updated(
|
||||
hass: HomeAssistant, updated_entry: ConfigEntry
|
||||
) -> None:
|
||||
# Trigger entity refresh so attribute changes (e.g. duration) show up.
|
||||
controller.async_publish_update()
|
||||
|
||||
entry.async_on_unload(entry.add_update_listener(_async_on_options_updated))
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: MainGateConfigEntry) -> bool:
|
||||
"""Unload a config entry, cancelling any in-progress gate cycle."""
|
||||
controller: MainGateController = entry.runtime_data
|
||||
await controller.async_shutdown()
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
Reference in New Issue
Block a user