Refactor goalzero (#53282)

This commit is contained in:
Robert Hillis 2021-07-21 14:52:17 -04:00 committed by GitHub
parent fd2f15b7c7
commit 3eb3c2824c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 44 deletions

View file

@ -1,6 +1,6 @@
"""Support for Goal Zero Yeti Sensors."""
from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.const import CONF_NAME
from homeassistant.const import ATTR_DEVICE_CLASS, ATTR_ICON, ATTR_NAME, CONF_NAME
from . import YetiEntity
from .const import BINARY_SENSOR_DICT, DATA_KEY_API, DATA_KEY_COORDINATOR, DOMAIN
@ -39,21 +39,12 @@ class YetiBinarySensor(YetiEntity, BinarySensorEntity):
super().__init__(api, coordinator, name, server_unique_id)
self._condition = sensor_name
variable_info = BINARY_SENSOR_DICT[sensor_name]
self._condition_name = variable_info[0]
self._icon = variable_info[2]
self._device_class = variable_info[1]
@property
def name(self) -> str:
"""Return the name of the sensor."""
return f"{self._name} {self._condition_name}"
@property
def unique_id(self) -> str:
"""Return the unique id of the sensor."""
return f"{self._server_unique_id}/{self._condition_name}"
self._attr_device_class = BINARY_SENSOR_DICT[sensor_name].get(ATTR_DEVICE_CLASS)
self._attr_icon = BINARY_SENSOR_DICT[sensor_name].get(ATTR_ICON)
self._attr_name = f"{name} {BINARY_SENSOR_DICT[sensor_name].get(ATTR_NAME)}"
self._attr_unique_id = (
f"{server_unique_id}/{BINARY_SENSOR_DICT[sensor_name].get(ATTR_NAME)}"
)
@property
def is_on(self) -> bool:
@ -61,8 +52,3 @@ class YetiBinarySensor(YetiEntity, BinarySensorEntity):
if self.api.data:
return self.api.data[self._condition] == 1
return False
@property
def icon(self) -> str:
"""Icon to use in the frontend, if any."""
return self._icon