Perform some Flu Near You code cleanup (#58860)

This commit is contained in:
Aaron Bach 2021-11-14 11:10:05 -07:00 committed by GitHub
parent 595184aa55
commit 24c899cf50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 14 deletions

View File

@ -26,8 +26,6 @@ PLATFORMS = ["sensor"]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Flu Near You as config entry."""
hass.data.setdefault(DOMAIN, {})
websession = aiohttp_client.async_get_clientsession(hass)
client = Client(session=websession)
@ -64,6 +62,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
data_init_tasks.append(coordinator.async_refresh())
await asyncio.gather(*data_init_tasks)
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.entry_id] = coordinators
hass.config_entries.async_setup_platforms(entry, PLATFORMS)

View File

@ -10,12 +10,7 @@ from homeassistant.components.sensor import (
SensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_ATTRIBUTION,
ATTR_STATE,
CONF_LATITUDE,
CONF_LONGITUDE,
)
from homeassistant.const import ATTR_STATE, CONF_LATITUDE, CONF_LONGITUDE
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
@ -34,8 +29,6 @@ ATTR_STATE_REPORTS_LAST_WEEK = "state_reports_last_week"
ATTR_STATE_REPORTS_THIS_WEEK = "state_reports_this_week"
ATTR_ZIP_CODE = "zip_code"
DEFAULT_ATTRIBUTION = "Data provided by Flu Near You"
SENSOR_TYPE_CDC_LEVEL = "level"
SENSOR_TYPE_CDC_LEVEL2 = "level2"
SENSOR_TYPE_USER_CHICK = "chick"
@ -140,8 +133,6 @@ async def async_setup_entry(
class FluNearYouSensor(CoordinatorEntity, SensorEntity):
"""Define a base Flu Near You sensor."""
DEFAULT_EXTRA_STATE_ATTRIBUTES = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
def __init__(
self,
coordinator: DataUpdateCoordinator,
@ -166,7 +157,6 @@ class CdcSensor(FluNearYouSensor):
def extra_state_attributes(self) -> Mapping[str, Any] | None:
"""Return entity specific state attributes."""
return {
**self.DEFAULT_EXTRA_STATE_ATTRIBUTES,
ATTR_REPORTED_DATE: self.coordinator.data["week_date"],
ATTR_STATE: self.coordinator.data["name"],
}
@ -186,7 +176,6 @@ class UserSensor(FluNearYouSensor):
def extra_state_attributes(self) -> Mapping[str, Any] | None:
"""Return entity specific state attributes."""
attrs = {
**self.DEFAULT_EXTRA_STATE_ATTRIBUTES,
ATTR_CITY: self.coordinator.data["local"]["city"].split("(")[0],
ATTR_REPORTED_LATITUDE: self.coordinator.data["local"]["latitude"],
ATTR_REPORTED_LONGITUDE: self.coordinator.data["local"]["longitude"],