mirror of
https://github.com/home-assistant/core.git
synced 2025-08-05 21:55:10 +02:00
Adjust callback registration
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@@ -108,6 +109,11 @@ class I2CHatBinarySensor(BinarySensorEntity):
|
|||||||
self._device_class = device_class
|
self._device_class = device_class
|
||||||
self._state = self.I2C_HATS_MANAGER.read_di(self._address, self._channel)
|
self._state = self.I2C_HATS_MANAGER.read_di(self._address, self._channel)
|
||||||
|
|
||||||
|
async def async_added_to_hass(self) -> None:
|
||||||
|
"""Register callbacks."""
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
assert self.I2C_HATS_MANAGER
|
||||||
|
|
||||||
def online_callback():
|
def online_callback():
|
||||||
"""Call fired when board is online."""
|
"""Call fired when board is online."""
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@@ -108,6 +109,11 @@ class I2CHatSwitch(ToggleEntity):
|
|||||||
state = initial_state
|
state = initial_state
|
||||||
self.I2C_HATS_MANAGER.write_dq(self._address, self._channel, state)
|
self.I2C_HATS_MANAGER.write_dq(self._address, self._channel, state)
|
||||||
|
|
||||||
|
async def async_added_to_hass(self) -> None:
|
||||||
|
"""Register callbacks."""
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
assert self.I2C_HATS_MANAGER
|
||||||
|
|
||||||
def online_callback():
|
def online_callback():
|
||||||
"""Call fired when board is online."""
|
"""Call fired when board is online."""
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
Reference in New Issue
Block a user