mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
Handle stale switchbot advertisement data while connected (#77956)
This commit is contained in:
parent
645f5e5ac1
commit
2cfdc15c38
@ -4,6 +4,8 @@ from __future__ import annotations
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
import switchbot
|
||||
|
||||
from homeassistant.components.cover import (
|
||||
ATTR_CURRENT_POSITION,
|
||||
ATTR_POSITION,
|
||||
@ -36,6 +38,7 @@ async def async_setup_entry(
|
||||
class SwitchBotCurtainEntity(SwitchbotEntity, CoverEntity, RestoreEntity):
|
||||
"""Representation of a Switchbot."""
|
||||
|
||||
_device: switchbot.SwitchbotCurtain
|
||||
_attr_device_class = CoverDeviceClass.CURTAIN
|
||||
_attr_supported_features = (
|
||||
CoverEntityFeature.OPEN
|
||||
|
@ -2,7 +2,7 @@
|
||||
"domain": "switchbot",
|
||||
"name": "SwitchBot",
|
||||
"documentation": "https://www.home-assistant.io/integrations/switchbot",
|
||||
"requirements": ["PySwitchbot==0.18.25"],
|
||||
"requirements": ["PySwitchbot==0.18.27"],
|
||||
"config_flow": true,
|
||||
"dependencies": ["bluetooth"],
|
||||
"codeowners": [
|
||||
|
@ -4,6 +4,8 @@ from __future__ import annotations
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
import switchbot
|
||||
|
||||
from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import STATE_ON
|
||||
@ -34,6 +36,7 @@ class SwitchBotSwitch(SwitchbotEntity, SwitchEntity, RestoreEntity):
|
||||
"""Representation of a Switchbot switch."""
|
||||
|
||||
_attr_device_class = SwitchDeviceClass.SWITCH
|
||||
_device: switchbot.Switchbot
|
||||
|
||||
def __init__(self, coordinator: SwitchbotDataUpdateCoordinator) -> None:
|
||||
"""Initialize the Switchbot."""
|
||||
@ -69,21 +72,19 @@ class SwitchBotSwitch(SwitchbotEntity, SwitchEntity, RestoreEntity):
|
||||
@property
|
||||
def assumed_state(self) -> bool:
|
||||
"""Return true if unable to access real state of entity."""
|
||||
if not self.data["data"]["switchMode"]:
|
||||
return True
|
||||
return False
|
||||
return not self._device.switch_mode()
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool | None:
|
||||
"""Return true if device is on."""
|
||||
if not self.data["data"]["switchMode"]:
|
||||
if not self._device.switch_mode():
|
||||
return self._attr_is_on
|
||||
return self.data["data"]["isOn"]
|
||||
return self._device.is_on()
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict:
|
||||
"""Return the state attributes."""
|
||||
return {
|
||||
**super().extra_state_attributes,
|
||||
"switch_mode": self.data["data"]["switchMode"],
|
||||
"switch_mode": self._device.switch_mode(),
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ PyRMVtransport==0.3.3
|
||||
PySocks==1.7.1
|
||||
|
||||
# homeassistant.components.switchbot
|
||||
PySwitchbot==0.18.25
|
||||
PySwitchbot==0.18.27
|
||||
|
||||
# homeassistant.components.transport_nsw
|
||||
PyTransportNSW==0.1.1
|
||||
|
@ -33,7 +33,7 @@ PyRMVtransport==0.3.3
|
||||
PySocks==1.7.1
|
||||
|
||||
# homeassistant.components.switchbot
|
||||
PySwitchbot==0.18.25
|
||||
PySwitchbot==0.18.27
|
||||
|
||||
# homeassistant.components.transport_nsw
|
||||
PyTransportNSW==0.1.1
|
||||
|
Loading…
x
Reference in New Issue
Block a user