Skip to content

Commit

Permalink
Fixing device_state_attribute
Browse files Browse the repository at this point in the history
Also, running pre-commit hooks on all the files
  • Loading branch information
valleedelisle committed Dec 23, 2021
1 parent 533e1d2 commit 20b6692
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 56 deletions.
57 changes: 38 additions & 19 deletions custom_components/hilo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,56 @@
from typing import TYPE_CHECKING, Union

from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.components.utility_meter.const import ATTR_TARIFF
from homeassistant.components.utility_meter.const import \
DOMAIN as UTIL_METER_DOMAIN
from homeassistant.components.utility_meter.const import SERVICE_SELECT_TARIFF
from homeassistant.components.utility_meter.const import (
ATTR_TARIFF,
DOMAIN as UTIL_METER_DOMAIN,
SERVICE_SELECT_TARIFF,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (ATTR_DEVICE_CLASS, ATTR_UNIT_OF_MEASUREMENT,
CONF_PASSWORD, CONF_TOKEN,
CONF_USERNAME, DEVICE_CLASS_ENERGY,
EVENT_HOMEASSISTANT_STOP)
from homeassistant.const import (
ATTR_DEVICE_CLASS,
ATTR_UNIT_OF_MEASUREMENT,
CONF_PASSWORD,
CONF_TOKEN,
CONF_USERNAME,
DEVICE_CLASS_ENERGY,
EVENT_HOMEASSISTANT_STOP,
)
from homeassistant.core import Context, Event, HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from homeassistant.helpers import aiohttp_client
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.dispatcher import (async_dispatcher_connect,
async_dispatcher_send)
from homeassistant.helpers import aiohttp_client, device_registry as dr
from homeassistant.helpers.dispatcher import (
async_dispatcher_connect,
async_dispatcher_send,
)
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.event import async_call_later
from homeassistant.helpers.service import verify_domain_control
from homeassistant.helpers.update_coordinator import (CoordinatorEntity,
DataUpdateCoordinator)
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
)
from pyhilo import API
from pyhilo.device import HiloDevice
from pyhilo.devices import Devices
from pyhilo.exceptions import (HiloError, InvalidCredentialsError,
WebsocketClosed, WebsocketError)
from pyhilo.exceptions import (
HiloError,
InvalidCredentialsError,
WebsocketClosed,
WebsocketError,
)
from pyhilo.util import from_utc_timestamp, time_diff
from pyhilo.websocket import WebsocketEvent

from .config_flow import STEP_OPTION_SCHEMA
from .const import (CONF_HIGH_PERIODS, CONF_HQ_PLAN_NAME, CONF_TARIFF,
DEFAULT_HQ_PLAN_NAME, DEFAULT_SCAN_INTERVAL, DOMAIN, LOG)
from .const import (
CONF_HIGH_PERIODS,
CONF_HQ_PLAN_NAME,
CONF_TARIFF,
DEFAULT_HQ_PLAN_NAME,
DEFAULT_SCAN_INTERVAL,
DOMAIN,
LOG,
)

DISPATCHER_TOPIC_WEBSOCKET_EVENT = "pyhilo_websocket_event"
SIGNAL_UPDATE_ENTITY = "pyhilo_device_update_{}"
Expand Down
11 changes: 6 additions & 5 deletions custom_components/hilo/climate.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate.const import (HVAC_MODE_HEAT,
HVAC_MODE_OFF,
SUPPORT_TARGET_TEMPERATURE)
from homeassistant.components.climate.const import (
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
SUPPORT_TARGET_TEMPERATURE,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (ATTR_TEMPERATURE, PRECISION_TENTHS,
TEMP_CELSIUS)
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_TENTHS, TEMP_CELSIUS
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util import slugify
Expand Down
27 changes: 18 additions & 9 deletions custom_components/hilo/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,32 @@

from typing import Any

import voluptuous as vol
from homeassistant import config_entries
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_TOKEN,
CONF_USERNAME)
from homeassistant.const import (
CONF_PASSWORD,
CONF_SCAN_INTERVAL,
CONF_TOKEN,
CONF_USERNAME,
)
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers import aiohttp_client
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers import aiohttp_client, config_validation as cv
from homeassistant.helpers.typing import ConfigType
from pyhilo import API
from pyhilo.exceptions import HiloError, InvalidCredentialsError
import voluptuous as vol

from .const import (CONF_GENERATE_ENERGY_METERS,
CONF_HQ_PLAN_NAME,
DEFAULT_GENERATE_ENERGY_METERS, DEFAULT_HQ_PLAN_NAME,
DEFAULT_SCAN_INTERVAL, DOMAIN, LOG, MIN_SCAN_INTERVAL)
from .const import (
CONF_GENERATE_ENERGY_METERS,
CONF_HQ_PLAN_NAME,
DEFAULT_GENERATE_ENERGY_METERS,
DEFAULT_HQ_PLAN_NAME,
DEFAULT_SCAN_INTERVAL,
DOMAIN,
LOG,
MIN_SCAN_INTERVAL,
)

STEP_USER_SCHEMA = vol.Schema(
{
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hilo/const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from datetime import time
import logging

from homeassistant.components.utility_meter.const import DAILY

Expand Down
9 changes: 6 additions & 3 deletions custom_components/hilo/light.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from homeassistant.components.light import (ATTR_BRIGHTNESS,
COLOR_MODE_BRIGHTNESS,
COLOR_MODE_ONOFF, LightEntity)
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
COLOR_MODE_BRIGHTNESS,
COLOR_MODE_ONOFF,
LightEntity,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand Down
8 changes: 4 additions & 4 deletions custom_components/hilo/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

from homeassistant.components.energy.data import async_get_manager
from homeassistant.components.utility_meter import async_setup as utility_setup
from homeassistant.components.utility_meter.const import \
DOMAIN as UTILITY_DOMAIN
from homeassistant.components.utility_meter.sensor import \
async_setup_platform as utility_setup_platform
from homeassistant.components.utility_meter.const import DOMAIN as UTILITY_DOMAIN
from homeassistant.components.utility_meter.sensor import (
async_setup_platform as utility_setup_platform,
)

from .const import LOG, TARIFF_LIST

Expand Down
44 changes: 29 additions & 15 deletions custom_components/hilo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,43 @@

from datetime import timedelta

import homeassistant.util.dt as dt_util
from homeassistant.components.integration.sensor import (TRAPEZOIDAL_METHOD,
IntegrationSensor)
from homeassistant.components.sensor import (STATE_CLASS_MEASUREMENT,
SensorEntity)
from homeassistant.components.integration.sensor import (
TRAPEZOIDAL_METHOD,
IntegrationSensor,
)
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (CONF_SCAN_INTERVAL, DEVICE_CLASS_ENERGY,
DEVICE_CLASS_POWER, DEVICE_CLASS_TEMPERATURE,
ENERGY_KILO_WATT_HOUR, ENERGY_WATT_HOUR,
POWER_WATT, TEMP_CELSIUS)
from homeassistant.const import (
CONF_SCAN_INTERVAL,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_POWER,
DEVICE_CLASS_TEMPERATURE,
ENERGY_KILO_WATT_HOUR,
ENERGY_WATT_HOUR,
POWER_WATT,
TEMP_CELSIUS,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.util import Throttle, slugify
import homeassistant.util.dt as dt_util
from pyhilo.device import HiloDevice
from pyhilo.util.hilo import event_parsing

from . import Hilo, HiloEntity
from .const import (CONF_ENERGY_METER_PERIOD, CONF_GENERATE_ENERGY_METERS,
CONF_HQ_PLAN_NAME, CONF_TARIFF,
DEFAULT_ENERGY_METER_PERIOD,
DEFAULT_GENERATE_ENERGY_METERS, DEFAULT_HQ_PLAN_NAME,
DEFAULT_SCAN_INTERVAL, DOMAIN, LOG)
from .const import (
CONF_ENERGY_METER_PERIOD,
CONF_GENERATE_ENERGY_METERS,
CONF_HQ_PLAN_NAME,
CONF_TARIFF,
DEFAULT_ENERGY_METER_PERIOD,
DEFAULT_GENERATE_ENERGY_METERS,
DEFAULT_HQ_PLAN_NAME,
DEFAULT_SCAN_INTERVAL,
DOMAIN,
LOG,
)
from .managers import EnergyManager, UtilityManager


Expand Down Expand Up @@ -310,7 +324,7 @@ def unit_of_measurement(self):
return "$/kWh"

@property
def device_state_attributes(self):
def extra_state_attributes(self):
return {"last_update": self._last_update, "Cost": self.state}

async def async_added_to_hass(self):
Expand Down

0 comments on commit 20b6692

Please sign in to comment.