mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
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
This commit is contained in:
parent
a7c7e58a5b
commit
0ad5ad5ca7
@ -68,6 +68,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
update_method=async_update_data,
|
update_method=async_update_data,
|
||||||
update_interval=MIN_TIME_BETWEEN_UPDATES,
|
update_interval=MIN_TIME_BETWEEN_UPDATES,
|
||||||
)
|
)
|
||||||
|
await coordinator.async_config_entry_first_refresh()
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][entry.entry_id] = {
|
hass.data[DOMAIN][entry.entry_id] = {
|
||||||
DATA_KEY_API: api,
|
DATA_KEY_API: api,
|
||||||
@ -112,6 +113,6 @@ class YetiEntity(CoordinatorEntity):
|
|||||||
ATTR_IDENTIFIERS: {(DOMAIN, self._server_unique_id)},
|
ATTR_IDENTIFIERS: {(DOMAIN, self._server_unique_id)},
|
||||||
ATTR_MANUFACTURER: "Goal Zero",
|
ATTR_MANUFACTURER: "Goal Zero",
|
||||||
ATTR_NAME: self._name,
|
ATTR_NAME: self._name,
|
||||||
ATTR_MODEL: self.api.sysdata.get(ATTR_MODEL),
|
ATTR_MODEL: self.api.sysdata[ATTR_MODEL],
|
||||||
ATTR_SW_VERSION: self.api.data.get("firmwareVersion"),
|
ATTR_SW_VERSION: self.api.data["firmwareVersion"],
|
||||||
}
|
}
|
||||||
|
@ -82,5 +82,5 @@ class YetiBinarySensor(YetiEntity, BinarySensorEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return if the service is on."""
|
"""Return True if the service is on."""
|
||||||
return cast(bool, self.api.data.get(self.entity_description.key) == 1)
|
return cast(bool, self.api.data[self.entity_description.key] == 1)
|
||||||
|
@ -31,6 +31,7 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
from homeassistant.helpers.typing import StateType
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
|
|
||||||
from . import Yeti, YetiEntity
|
from . import Yeti, YetiEntity
|
||||||
@ -170,6 +171,6 @@ class YetiSensor(YetiEntity, SensorEntity):
|
|||||||
self._attr_unique_id = f"{server_unique_id}/{description.key}"
|
self._attr_unique_id = f"{server_unique_id}/{description.key}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> str:
|
def native_value(self) -> StateType:
|
||||||
"""Return the state."""
|
"""Return the state."""
|
||||||
return cast(str, self.api.data.get(self.entity_description.key))
|
return cast(StateType, self.api.data[self.entity_description.key])
|
||||||
|
@ -67,7 +67,7 @@ class YetiSwitch(YetiEntity, SwitchEntity):
|
|||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return state of the switch."""
|
"""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:
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Turn off the switch."""
|
"""Turn off the switch."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user