mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
Add last_run_success boolean attribute to Switchbot for error trapping (#25474)
* Add last_run_error boolean attribute to Switchbot entity to allow for trapping of errors * Add last_run_success boolean attribute to Switchbot for error trapping * Add last_run_success boolean attribute to Switchbot for error trapping
This commit is contained in:
parent
4d7fd8ae17
commit
0be0353eed
@ -1,5 +1,6 @@
|
|||||||
"""Support for Switchbot."""
|
"""Support for Switchbot."""
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any, Dict
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -36,6 +37,7 @@ class SwitchBot(SwitchDevice, RestoreEntity):
|
|||||||
import switchbot
|
import switchbot
|
||||||
|
|
||||||
self._state = None
|
self._state = None
|
||||||
|
self._last_run_success = None
|
||||||
self._name = name
|
self._name = name
|
||||||
self._mac = mac
|
self._mac = mac
|
||||||
self._device = switchbot.Switchbot(mac=mac)
|
self._device = switchbot.Switchbot(mac=mac)
|
||||||
@ -52,11 +54,17 @@ class SwitchBot(SwitchDevice, RestoreEntity):
|
|||||||
"""Turn device on."""
|
"""Turn device on."""
|
||||||
if self._device.turn_on():
|
if self._device.turn_on():
|
||||||
self._state = True
|
self._state = True
|
||||||
|
self._last_run_success = True
|
||||||
|
else:
|
||||||
|
self._last_run_success = False
|
||||||
|
|
||||||
def turn_off(self, **kwargs) -> None:
|
def turn_off(self, **kwargs) -> None:
|
||||||
"""Turn device off."""
|
"""Turn device off."""
|
||||||
if self._device.turn_off():
|
if self._device.turn_off():
|
||||||
self._state = False
|
self._state = False
|
||||||
|
self._last_run_success = True
|
||||||
|
else:
|
||||||
|
self._last_run_success = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def assumed_state(self) -> bool:
|
def assumed_state(self) -> bool:
|
||||||
@ -77,3 +85,8 @@ class SwitchBot(SwitchDevice, RestoreEntity):
|
|||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Return the name of the switch."""
|
"""Return the name of the switch."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_state_attributes(self) -> Dict[str, Any]:
|
||||||
|
"""Return the state attributes."""
|
||||||
|
return {'last_run_success': self._last_run_success}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user