mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 00:07:10 +00:00
Use short-hand attributes in remote-rpi-gpio (#140263)
This commit is contained in:
parent
e831b1b230
commit
25f15c1149
@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from gpiozero import DigitalInputDevice
|
||||
import requests
|
||||
import voluptuous as vol
|
||||
|
||||
@ -48,10 +49,10 @@ def setup_platform(
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the Raspberry PI GPIO devices."""
|
||||
address = config["host"]
|
||||
address = config[CONF_HOST]
|
||||
invert_logic = config[CONF_INVERT_LOGIC]
|
||||
pull_mode = config[CONF_PULL_MODE]
|
||||
ports = config["ports"]
|
||||
ports = config[CONF_PORTS]
|
||||
bouncetime = config[CONF_BOUNCETIME] / 1000
|
||||
|
||||
devices = []
|
||||
@ -71,9 +72,11 @@ class RemoteRPiGPIOBinarySensor(BinarySensorEntity):
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, name, sensor, invert_logic):
|
||||
def __init__(
|
||||
self, name: str | None, sensor: DigitalInputDevice, invert_logic: bool
|
||||
) -> None:
|
||||
"""Initialize the RPi binary sensor."""
|
||||
self._name = name
|
||||
self._attr_name = name
|
||||
self._invert_logic = invert_logic
|
||||
self._state = False
|
||||
self._sensor = sensor
|
||||
@ -90,20 +93,10 @@ class RemoteRPiGPIOBinarySensor(BinarySensorEntity):
|
||||
self._sensor.when_activated = read_gpio
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
def is_on(self) -> bool:
|
||||
"""Return the state of the entity."""
|
||||
return self._state != self._invert_logic
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the class of this sensor, from DEVICE_CLASSES."""
|
||||
return
|
||||
|
||||
def update(self) -> None:
|
||||
"""Update the GPIO state."""
|
||||
try:
|
||||
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from gpiozero import LED
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.switch import (
|
||||
@ -57,37 +58,23 @@ def setup_platform(
|
||||
class RemoteRPiGPIOSwitch(SwitchEntity):
|
||||
"""Representation of a Remote Raspberry Pi GPIO."""
|
||||
|
||||
_attr_assumed_state = True
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, name, led):
|
||||
def __init__(self, name: str | None, led: LED) -> None:
|
||||
"""Initialize the pin."""
|
||||
self._name = name or DEVICE_DEFAULT_NAME
|
||||
self._state = False
|
||||
self._attr_name = name or DEVICE_DEFAULT_NAME
|
||||
self._attr_is_on = False
|
||||
self._switch = led
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the switch."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def assumed_state(self):
|
||||
"""If unable to access real state of the entity."""
|
||||
return True
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if device is on."""
|
||||
return self._state
|
||||
|
||||
def turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn the device on."""
|
||||
write_output(self._switch, 1)
|
||||
self._state = True
|
||||
self._attr_is_on = True
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn the device off."""
|
||||
write_output(self._switch, 0)
|
||||
self._state = False
|
||||
self._attr_is_on = False
|
||||
self.schedule_update_ha_state()
|
||||
|
Loading…
x
Reference in New Issue
Block a user