Don't use cast when possible for goalzero (#57742)

* Don't use cast when possible for goalzero

* tweak

* tweak

* tweak

* Call first refresh on coordinator

* don't use dict.get if not needed

* tweak
pull/57820/head
Robert Hillis 2021-10-15 17:34:13 -04:00 committed by GitHub
parent a7c7e58a5b
commit 0ad5ad5ca7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 7 deletions

View File

@ -68,6 +68,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
update_method=async_update_data,
update_interval=MIN_TIME_BETWEEN_UPDATES,
)
await coordinator.async_config_entry_first_refresh()
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.entry_id] = {
DATA_KEY_API: api,
@ -112,6 +113,6 @@ class YetiEntity(CoordinatorEntity):
ATTR_IDENTIFIERS: {(DOMAIN, self._server_unique_id)},
ATTR_MANUFACTURER: "Goal Zero",
ATTR_NAME: self._name,
ATTR_MODEL: self.api.sysdata.get(ATTR_MODEL),
ATTR_SW_VERSION: self.api.data.get("firmwareVersion"),
ATTR_MODEL: self.api.sysdata[ATTR_MODEL],
ATTR_SW_VERSION: self.api.data["firmwareVersion"],
}

View File

@ -82,5 +82,5 @@ class YetiBinarySensor(YetiEntity, BinarySensorEntity):
@property
def is_on(self) -> bool:
"""Return if the service is on."""
return cast(bool, self.api.data.get(self.entity_description.key) == 1)
"""Return True if the service is on."""
return cast(bool, self.api.data[self.entity_description.key] == 1)

View File

@ -31,6 +31,7 @@ from homeassistant.const import (
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from . import Yeti, YetiEntity
@ -170,6 +171,6 @@ class YetiSensor(YetiEntity, SensorEntity):
self._attr_unique_id = f"{server_unique_id}/{description.key}"
@property
def native_value(self) -> str:
def native_value(self) -> StateType:
"""Return the state."""
return cast(str, self.api.data.get(self.entity_description.key))
return cast(StateType, self.api.data[self.entity_description.key])

View File

@ -67,7 +67,7 @@ class YetiSwitch(YetiEntity, SwitchEntity):
@property
def is_on(self) -> bool:
"""Return state of the switch."""
return cast(bool, self.api.data.get(self.entity_description.key))
return cast(bool, self.api.data[self.entity_description.key] == 1)
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn off the switch."""