forked from home-assistant/core
Address late review of Switcher sensor migration (#52186)
This commit is contained in:
@@ -13,7 +13,7 @@ from homeassistant.components.sensor import (
|
|||||||
SensorEntity,
|
SensorEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ELECTRICAL_CURRENT_AMPERE, POWER_WATT
|
from homeassistant.const import ELECTRICAL_CURRENT_AMPERE, POWER_WATT
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import DiscoveryInfoType, StateType
|
from homeassistant.helpers.typing import DiscoveryInfoType, StateType
|
||||||
@@ -124,8 +124,8 @@ class SwitcherSensorEntity(SensorEntity):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_update_data(self, device_data: SwitcherV2Device) -> None:
|
@callback
|
||||||
|
def async_update_data(self, device_data: SwitcherV2Device) -> None:
|
||||||
"""Update the entity data."""
|
"""Update the entity data."""
|
||||||
if device_data:
|
self._device_data = device_data
|
||||||
self._device_data = device_data
|
self.async_write_ha_state()
|
||||||
self.async_write_ha_state()
|
|
||||||
|
@@ -13,7 +13,7 @@ from aioswitcher.devices import SwitcherV2Device
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchEntity
|
from homeassistant.components.switch import SwitchEntity
|
||||||
from homeassistant.core import HomeAssistant, ServiceCall
|
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
@@ -135,15 +135,15 @@ class SwitcherControl(SwitchEntity):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_update_data(self, device_data: SwitcherV2Device) -> None:
|
@callback
|
||||||
|
def async_update_data(self, device_data: SwitcherV2Device) -> None:
|
||||||
"""Update the entity data."""
|
"""Update the entity data."""
|
||||||
if device_data:
|
if self._self_initiated:
|
||||||
if self._self_initiated:
|
self._self_initiated = False
|
||||||
self._self_initiated = False
|
else:
|
||||||
else:
|
self._device_data = device_data
|
||||||
self._device_data = device_data
|
self._state = self._device_data.state
|
||||||
self._state = self._device_data.state
|
self.async_write_ha_state()
|
||||||
self.async_write_ha_state()
|
|
||||||
|
|
||||||
async def async_turn_on(self, **kwargs: dict) -> None:
|
async def async_turn_on(self, **kwargs: dict) -> None:
|
||||||
"""Turn the entity on."""
|
"""Turn the entity on."""
|
||||||
|
Reference in New Issue
Block a user