Use entity class attributes for bbb_gpio (#52837)
This commit is contained in:
parent
d7b2ec80b2
commit
d01227f141
2 changed files with 8 additions and 24 deletions
|
@ -43,10 +43,12 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
class BBBGPIOBinarySensor(BinarySensorEntity):
|
||||
"""Representation of a binary sensor that uses Beaglebone Black GPIO."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, pin, params):
|
||||
"""Initialize the Beaglebone Black binary sensor."""
|
||||
self._pin = pin
|
||||
self._name = params[CONF_NAME] or DEVICE_DEFAULT_NAME
|
||||
self._attr_name = params[CONF_NAME] or DEVICE_DEFAULT_NAME
|
||||
self._bouncetime = params[CONF_BOUNCETIME]
|
||||
self._pull_mode = params[CONF_PULL_MODE]
|
||||
self._invert_logic = params[CONF_INVERT_LOGIC]
|
||||
|
@ -62,16 +64,6 @@ class BBBGPIOBinarySensor(BinarySensorEntity):
|
|||
bbb_gpio.edge_detect(self._pin, read_gpio, self._bouncetime)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""No polling needed."""
|
||||
return False
|
||||
|
||||
@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
|
||||
|
|
|
@ -37,10 +37,12 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
class BBBGPIOSwitch(ToggleEntity):
|
||||
"""Representation of a BeagleBone Black GPIO."""
|
||||
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, pin, params):
|
||||
"""Initialize the pin."""
|
||||
self._pin = pin
|
||||
self._name = params[CONF_NAME] or DEVICE_DEFAULT_NAME
|
||||
self._attr_name = params[CONF_NAME] or DEVICE_DEFAULT_NAME
|
||||
self._state = params[CONF_INITIAL]
|
||||
self._invert_logic = params[CONF_INVERT_LOGIC]
|
||||
|
||||
|
@ -52,17 +54,7 @@ class BBBGPIOSwitch(ToggleEntity):
|
|||
bbb_gpio.write_output(self._pin, 0 if self._invert_logic else 1)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the switch."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""No polling needed."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
def is_on(self) -> bool:
|
||||
"""Return true if device is on."""
|
||||
return self._state
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue