mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Use shorthand attributes in raspyrfm (#145250)
This commit is contained in:
parent
eb90f5a581
commit
f700a1faa3
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from raspyrfm_client import RaspyRFMClient
|
from raspyrfm_client import RaspyRFMClient
|
||||||
from raspyrfm_client.device_implementations.controlunit.actions import Action
|
from raspyrfm_client.device_implementations.controlunit.actions import Action
|
||||||
from raspyrfm_client.device_implementations.controlunit.controlunit_constants import (
|
from raspyrfm_client.device_implementations.controlunit.controlunit_constants import (
|
||||||
@ -100,41 +102,27 @@ def setup_platform(
|
|||||||
class RaspyRFMSwitch(SwitchEntity):
|
class RaspyRFMSwitch(SwitchEntity):
|
||||||
"""Representation of a RaspyRFM switch."""
|
"""Representation of a RaspyRFM switch."""
|
||||||
|
|
||||||
|
_attr_assumed_state = True
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(self, raspyrfm_client, name: str, gateway, controlunit) -> None:
|
def __init__(self, raspyrfm_client, name: str, gateway, controlunit) -> None:
|
||||||
"""Initialize the switch."""
|
"""Initialize the switch."""
|
||||||
self._raspyrfm_client = raspyrfm_client
|
self._raspyrfm_client = raspyrfm_client
|
||||||
|
|
||||||
self._name = name
|
self._attr_name = name
|
||||||
self._gateway = gateway
|
self._gateway = gateway
|
||||||
self._controlunit = controlunit
|
self._controlunit = controlunit
|
||||||
|
|
||||||
self._state = None
|
self._attr_is_on = None
|
||||||
|
|
||||||
@property
|
def turn_on(self, **kwargs: Any) -> None:
|
||||||
def name(self):
|
|
||||||
"""Return the name of the device if any."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def assumed_state(self) -> bool:
|
|
||||||
"""Return True when the current state cannot be queried."""
|
|
||||||
return True
|
|
||||||
|
|
||||||
@property
|
|
||||||
def is_on(self):
|
|
||||||
"""Return true if switch is on."""
|
|
||||||
return self._state
|
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
|
||||||
"""Turn the switch on."""
|
"""Turn the switch on."""
|
||||||
|
|
||||||
self._raspyrfm_client.send(self._gateway, self._controlunit, Action.ON)
|
self._raspyrfm_client.send(self._gateway, self._controlunit, Action.ON)
|
||||||
self._state = True
|
self._attr_is_on = True
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Turn the switch off."""
|
"""Turn the switch off."""
|
||||||
|
|
||||||
if Action.OFF in self._controlunit.get_supported_actions():
|
if Action.OFF in self._controlunit.get_supported_actions():
|
||||||
@ -142,5 +130,5 @@ class RaspyRFMSwitch(SwitchEntity):
|
|||||||
else:
|
else:
|
||||||
self._raspyrfm_client.send(self._gateway, self._controlunit, Action.ON)
|
self._raspyrfm_client.send(self._gateway, self._controlunit, Action.ON)
|
||||||
|
|
||||||
self._state = False
|
self._attr_is_on = False
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user