Perform some WattTime code cleanup (#58869)
This commit is contained in:
parent
39054d656b
commit
5836a39f14
3 changed files with 5 additions and 19 deletions
|
@ -19,7 +19,7 @@ from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||||
from homeassistant.helpers import aiohttp_client
|
from homeassistant.helpers import aiohttp_client
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
from .const import DATA_COORDINATOR, DOMAIN, LOGGER
|
from .const import DOMAIN, LOGGER
|
||||||
|
|
||||||
DEFAULT_UPDATE_INTERVAL = timedelta(minutes=5)
|
DEFAULT_UPDATE_INTERVAL = timedelta(minutes=5)
|
||||||
|
|
||||||
|
@ -28,9 +28,6 @@ PLATFORMS: list[str] = ["sensor"]
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up WattTime from a config entry."""
|
"""Set up WattTime from a config entry."""
|
||||||
hass.data.setdefault(DOMAIN, {})
|
|
||||||
hass.data[DOMAIN][entry.entry_id] = {}
|
|
||||||
|
|
||||||
session = aiohttp_client.async_get_clientsession(hass)
|
session = aiohttp_client.async_get_clientsession(hass)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -65,7 +62,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
)
|
)
|
||||||
|
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
hass.data[DOMAIN][entry.entry_id][DATA_COORDINATOR] = coordinator
|
hass.data.setdefault(DOMAIN, {})
|
||||||
|
hass.data[DOMAIN][entry.entry_id] = coordinator
|
||||||
|
|
||||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
|
|
||||||
|
|
|
@ -8,5 +8,3 @@ LOGGER = logging.getLogger(__package__)
|
||||||
CONF_BALANCING_AUTHORITY = "balancing_authority"
|
CONF_BALANCING_AUTHORITY = "balancing_authority"
|
||||||
CONF_BALANCING_AUTHORITY_ABBREV = "balancing_authority_abbreviation"
|
CONF_BALANCING_AUTHORITY_ABBREV = "balancing_authority_abbreviation"
|
||||||
CONF_SHOW_ON_MAP = "show_on_map"
|
CONF_SHOW_ON_MAP = "show_on_map"
|
||||||
|
|
||||||
DATA_COORDINATOR = "coordinator"
|
|
||||||
|
|
|
@ -10,13 +10,7 @@ from homeassistant.components.sensor import (
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, MASS_POUNDS, PERCENTAGE
|
||||||
ATTR_ATTRIBUTION,
|
|
||||||
ATTR_LATITUDE,
|
|
||||||
ATTR_LONGITUDE,
|
|
||||||
MASS_POUNDS,
|
|
||||||
PERCENTAGE,
|
|
||||||
)
|
|
||||||
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.typing import StateType
|
||||||
|
@ -29,14 +23,11 @@ from .const import (
|
||||||
CONF_BALANCING_AUTHORITY,
|
CONF_BALANCING_AUTHORITY,
|
||||||
CONF_BALANCING_AUTHORITY_ABBREV,
|
CONF_BALANCING_AUTHORITY_ABBREV,
|
||||||
CONF_SHOW_ON_MAP,
|
CONF_SHOW_ON_MAP,
|
||||||
DATA_COORDINATOR,
|
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
|
|
||||||
ATTR_BALANCING_AUTHORITY = "balancing_authority"
|
ATTR_BALANCING_AUTHORITY = "balancing_authority"
|
||||||
|
|
||||||
DEFAULT_ATTRIBUTION = "Pickup data provided by WattTime"
|
|
||||||
|
|
||||||
SENSOR_TYPE_REALTIME_EMISSIONS_MOER = "moer"
|
SENSOR_TYPE_REALTIME_EMISSIONS_MOER = "moer"
|
||||||
SENSOR_TYPE_REALTIME_EMISSIONS_PERCENT = "percent"
|
SENSOR_TYPE_REALTIME_EMISSIONS_PERCENT = "percent"
|
||||||
|
|
||||||
|
@ -63,7 +54,7 @@ async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up WattTime sensors based on a config entry."""
|
"""Set up WattTime sensors based on a config entry."""
|
||||||
coordinator = hass.data[DOMAIN][entry.entry_id][DATA_COORDINATOR]
|
coordinator = hass.data[DOMAIN][entry.entry_id]
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
RealtimeEmissionsSensor(coordinator, entry, description)
|
RealtimeEmissionsSensor(coordinator, entry, description)
|
||||||
|
@ -96,7 +87,6 @@ class RealtimeEmissionsSensor(CoordinatorEntity, SensorEntity):
|
||||||
def extra_state_attributes(self) -> Mapping[str, Any] | None:
|
def extra_state_attributes(self) -> Mapping[str, Any] | None:
|
||||||
"""Return entity specific state attributes."""
|
"""Return entity specific state attributes."""
|
||||||
attrs = {
|
attrs = {
|
||||||
ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION,
|
|
||||||
ATTR_BALANCING_AUTHORITY: self._entry.data[CONF_BALANCING_AUTHORITY],
|
ATTR_BALANCING_AUTHORITY: self._entry.data[CONF_BALANCING_AUTHORITY],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue