From d01227f141bad57d1252ec8380fe18453458f529 Mon Sep 17 00:00:00 2001 From: Robert Hillis Date: Sun, 11 Jul 2021 16:35:36 -0400 Subject: [PATCH] Use entity class attributes for bbb_gpio (#52837) --- .../components/bbb_gpio/binary_sensor.py | 16 ++++------------ homeassistant/components/bbb_gpio/switch.py | 16 ++++------------ 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/homeassistant/components/bbb_gpio/binary_sensor.py b/homeassistant/components/bbb_gpio/binary_sensor.py index c772cf86f00..5fcaccd674e 100644 --- a/homeassistant/components/bbb_gpio/binary_sensor.py +++ b/homeassistant/components/bbb_gpio/binary_sensor.py @@ -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 diff --git a/homeassistant/components/bbb_gpio/switch.py b/homeassistant/components/bbb_gpio/switch.py index 03a9065a15b..3bed1d7db13 100644 --- a/homeassistant/components/bbb_gpio/switch.py +++ b/homeassistant/components/bbb_gpio/switch.py @@ -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