Add extra state attributes to goalzero (#52932)

* Add extra state attributes to goalzero

* tweak
pull/52814/head
Robert Hillis 2021-07-20 16:26:52 -04:00 committed by GitHub
parent 059a9bc8ed
commit a9b9c4f13c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 3 deletions

View File

@ -7,7 +7,7 @@ from homeassistant.components.binary_sensor import DOMAIN as DOMAIN_BINARY_SENSO
from homeassistant.components.sensor import DOMAIN as DOMAIN_SENSOR
from homeassistant.components.switch import DOMAIN as DOMAIN_SWITCH
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_NAME
from homeassistant.const import ATTR_ATTRIBUTION, CONF_HOST, CONF_NAME
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession
@ -17,7 +17,13 @@ from homeassistant.helpers.update_coordinator import (
UpdateFailed,
)
from .const import DATA_KEY_API, DATA_KEY_COORDINATOR, DOMAIN, MIN_TIME_BETWEEN_UPDATES
from .const import (
ATTRIBUTION,
DATA_KEY_API,
DATA_KEY_COORDINATOR,
DOMAIN,
MIN_TIME_BETWEEN_UPDATES,
)
_LOGGER = logging.getLogger(__name__)
@ -74,6 +80,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
class YetiEntity(CoordinatorEntity):
"""Representation of a Goal Zero Yeti entity."""
_attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION}
def __init__(self, api, coordinator, name, server_unique_id):
"""Initialize a Goal Zero Yeti entity."""
super().__init__(coordinator)

View File

@ -31,6 +31,7 @@ from homeassistant.const import (
TIME_SECONDS,
)
ATTRIBUTION = "Data provided by Goal Zero"
ATTR_DEFAULT_ENABLED = "default_enabled"
CONF_IDENTIFIERS = "identifiers"
@ -133,6 +134,14 @@ SENSOR_DICT = {
ATTR_UNIT_OF_MEASUREMENT: TIME_SECONDS,
ATTR_DEFAULT_ENABLED: False,
},
"ssid": {
ATTR_NAME: "Wi-Fi SSID",
ATTR_DEFAULT_ENABLED: False,
},
"ipAddr": {
ATTR_NAME: "IP Address",
ATTR_DEFAULT_ENABLED: False,
},
}
SWITCH_DICT = {

View File

@ -56,4 +56,4 @@ class YetiSensor(YetiEntity):
def state(self):
"""Return the state."""
if self.api.data:
return self.api.data[self._condition]
return self.api.data.get(self._condition)