1 """Support for binary sensor using RPi GPIO."""
3 from __future__
import annotations
6 import voluptuous
as vol
9 PLATFORM_SCHEMA
as BINARY_SENSOR_PLATFORM_SCHEMA,
31 _SENSORS_SCHEMA = vol.Schema({cv.positive_int: cv.string})
33 PLATFORM_SCHEMA = BINARY_SENSOR_PLATFORM_SCHEMA.extend(
35 vol.Required(CONF_HOST): cv.string,
36 vol.Required(CONF_PORTS): _SENSORS_SCHEMA,
37 vol.Optional(CONF_INVERT_LOGIC, default=DEFAULT_INVERT_LOGIC): cv.boolean,
38 vol.Optional(CONF_BOUNCETIME, default=DEFAULT_BOUNCETIME): cv.positive_int,
39 vol.Optional(CONF_PULL_MODE, default=DEFAULT_PULL_MODE): cv.string,
47 add_entities: AddEntitiesCallback,
48 discovery_info: DiscoveryInfoType |
None =
None,
50 """Set up the Raspberry PI GPIO devices."""
51 address = config[
"host"]
52 invert_logic = config[CONF_INVERT_LOGIC]
53 pull_mode = config[CONF_PULL_MODE]
54 ports = config[
"ports"]
55 bouncetime = config[CONF_BOUNCETIME] / 1000
58 for port_num, port_name
in ports.items():
60 remote_sensor =
setup_input(address, port_num, pull_mode, bouncetime)
61 except (ValueError, IndexError, KeyError, OSError):
64 devices.append(new_sensor)
70 """Represent a binary sensor that uses a Remote Raspberry Pi GPIO."""
72 _attr_should_poll =
False
74 def __init__(self, name, sensor, invert_logic):
75 """Initialize the RPi binary sensor."""
82 """Run when entity about to be added to hass."""
85 """Read state from GPIO."""
89 self.
_sensor_sensor.when_deactivated = read_gpio
90 self.
_sensor_sensor.when_activated = read_gpio
94 """Return the name of the sensor."""
95 return self.
_name_name
99 """Return the state of the entity."""
104 """Return the class of this sensor, from DEVICE_CLASSES."""
108 """Update the GPIO state."""
111 except requests.exceptions.ConnectionError:
def __init__(self, name, sensor, invert_logic)
None async_added_to_hass(self)
None schedule_update_ha_state(self, bool force_refresh=False)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)
def setup_input(address, port, pull_mode, bouncetime)