mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Use runtime_data in firmata (#137630)
This commit is contained in:
parent
ff42353e61
commit
bdc847c7ac
@ -122,6 +122,8 @@ CONFIG_SCHEMA = vol.Schema(
|
||||
{DOMAIN: vol.All(cv.ensure_list, [BOARD_CONFIG_SCHEMA])}, extra=vol.ALLOW_EXTRA
|
||||
)
|
||||
|
||||
type FirmataConfigEntry = ConfigEntry[FirmataBoard]
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the Firmata domain."""
|
||||
@ -158,11 +160,10 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, config_entry: FirmataConfigEntry
|
||||
) -> bool:
|
||||
"""Set up a Firmata board for a config entry."""
|
||||
if DOMAIN not in hass.data:
|
||||
hass.data[DOMAIN] = {}
|
||||
|
||||
_LOGGER.debug(
|
||||
"Setting up Firmata id %s, name %s, config %s",
|
||||
config_entry.entry_id,
|
||||
@ -175,13 +176,11 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||
if not await board.async_setup():
|
||||
return False
|
||||
|
||||
hass.data[DOMAIN][config_entry.entry_id] = board
|
||||
config_entry.runtime_data = board
|
||||
|
||||
async def handle_shutdown(event) -> None:
|
||||
"""Handle shutdown of board when Home Assistant shuts down."""
|
||||
# Ensure board was not already removed previously before shutdown
|
||||
if config_entry.entry_id in hass.data[DOMAIN]:
|
||||
await board.async_reset()
|
||||
await board.async_reset()
|
||||
|
||||
config_entry.async_on_unload(
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, handle_shutdown)
|
||||
@ -208,7 +207,9 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(
|
||||
hass: HomeAssistant, config_entry: FirmataConfigEntry
|
||||
) -> bool:
|
||||
"""Shutdown and close a Firmata board for a config entry."""
|
||||
_LOGGER.debug("Closing Firmata board %s", config_entry.data[CONF_NAME])
|
||||
results: list[bool] = []
|
||||
@ -220,6 +221,6 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
||||
results.append(
|
||||
await hass.config_entries.async_unload_platforms(config_entry, platforms)
|
||||
)
|
||||
results.append(await hass.data[DOMAIN].pop(config_entry.entry_id).async_reset())
|
||||
results.append(await config_entry.runtime_data.async_reset())
|
||||
|
||||
return False not in results
|
||||
|
@ -3,12 +3,12 @@
|
||||
import logging
|
||||
|
||||
from homeassistant.components.binary_sensor import BinarySensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_NAME, CONF_PIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import CONF_NEGATE_STATE, CONF_PIN_MODE, DOMAIN
|
||||
from . import FirmataConfigEntry
|
||||
from .const import CONF_NEGATE_STATE, CONF_PIN_MODE
|
||||
from .entity import FirmataPinEntity
|
||||
from .pin import FirmataBinaryDigitalInput, FirmataPinUsedException
|
||||
|
||||
@ -17,13 +17,13 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: FirmataConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Firmata binary sensors."""
|
||||
new_entities = []
|
||||
|
||||
board = hass.data[DOMAIN][config_entry.entry_id]
|
||||
board = config_entry.runtime_data
|
||||
for binary_sensor in board.binary_sensors:
|
||||
pin = binary_sensor[CONF_PIN]
|
||||
pin_mode = binary_sensor[CONF_PIN_MODE]
|
||||
|
@ -11,8 +11,9 @@ from homeassistant.const import CONF_MAXIMUM, CONF_MINIMUM, CONF_NAME, CONF_PIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import FirmataConfigEntry
|
||||
from .board import FirmataPinType
|
||||
from .const import CONF_INITIAL_STATE, CONF_PIN_MODE, DOMAIN
|
||||
from .const import CONF_INITIAL_STATE, CONF_PIN_MODE
|
||||
from .entity import FirmataPinEntity
|
||||
from .pin import FirmataBoardPin, FirmataPinUsedException, FirmataPWMOutput
|
||||
|
||||
@ -21,13 +22,13 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: FirmataConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Firmata lights."""
|
||||
new_entities = []
|
||||
|
||||
board = hass.data[DOMAIN][config_entry.entry_id]
|
||||
board = config_entry.runtime_data
|
||||
for light in board.lights:
|
||||
pin = light[CONF_PIN]
|
||||
pin_mode = light[CONF_PIN_MODE]
|
||||
|
@ -3,12 +3,12 @@
|
||||
import logging
|
||||
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_NAME, CONF_PIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import CONF_DIFFERENTIAL, CONF_PIN_MODE, DOMAIN
|
||||
from . import FirmataConfigEntry
|
||||
from .const import CONF_DIFFERENTIAL, CONF_PIN_MODE
|
||||
from .entity import FirmataPinEntity
|
||||
from .pin import FirmataAnalogInput, FirmataPinUsedException
|
||||
|
||||
@ -17,13 +17,13 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: FirmataConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Firmata sensors."""
|
||||
new_entities = []
|
||||
|
||||
board = hass.data[DOMAIN][config_entry.entry_id]
|
||||
board = config_entry.runtime_data
|
||||
for sensor in board.sensors:
|
||||
pin = sensor[CONF_PIN]
|
||||
pin_mode = sensor[CONF_PIN_MODE]
|
||||
|
@ -4,12 +4,12 @@ import logging
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_NAME, CONF_PIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import CONF_INITIAL_STATE, CONF_NEGATE_STATE, CONF_PIN_MODE, DOMAIN
|
||||
from . import FirmataConfigEntry
|
||||
from .const import CONF_INITIAL_STATE, CONF_NEGATE_STATE, CONF_PIN_MODE
|
||||
from .entity import FirmataPinEntity
|
||||
from .pin import FirmataBinaryDigitalOutput, FirmataPinUsedException
|
||||
|
||||
@ -18,13 +18,13 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: FirmataConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Firmata switches."""
|
||||
new_entities = []
|
||||
|
||||
board = hass.data[DOMAIN][config_entry.entry_id]
|
||||
board = config_entry.runtime_data
|
||||
for switch in board.switches:
|
||||
pin = switch[CONF_PIN]
|
||||
pin_mode = switch[CONF_PIN_MODE]
|
||||
|
Loading…
x
Reference in New Issue
Block a user