Use core constants for efergy (#46090)

pull/46202/head
tkdrob 2021-02-08 03:45:05 -05:00 committed by GitHub
parent 840891e4f4
commit 352bba1f15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 7 deletions

View File

@ -5,7 +5,13 @@ import requests
import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import CONF_CURRENCY, ENERGY_KILO_WATT_HOUR, POWER_WATT
from homeassistant.const import (
CONF_CURRENCY,
CONF_MONITORED_VARIABLES,
CONF_TYPE,
ENERGY_KILO_WATT_HOUR,
POWER_WATT,
)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
@ -14,8 +20,6 @@ _RESOURCE = "https://engage.efergy.com/mobile_proxy/"
CONF_APPTOKEN = "app_token"
CONF_UTC_OFFSET = "utc_offset"
CONF_MONITORED_VARIABLES = "monitored_variables"
CONF_SENSOR_TYPE = "type"
CONF_PERIOD = "period"
@ -40,7 +44,7 @@ TYPES_SCHEMA = vol.In(SENSOR_TYPES)
SENSORS_SCHEMA = vol.Schema(
{
vol.Required(CONF_SENSOR_TYPE): TYPES_SCHEMA,
vol.Required(CONF_TYPE): TYPES_SCHEMA,
vol.Optional(CONF_CURRENCY, default=""): cv.string,
vol.Optional(CONF_PERIOD, default=DEFAULT_PERIOD): cv.string,
}
@ -62,14 +66,14 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
dev = []
for variable in config[CONF_MONITORED_VARIABLES]:
if variable[CONF_SENSOR_TYPE] == CONF_CURRENT_VALUES:
if variable[CONF_TYPE] == CONF_CURRENT_VALUES:
url_string = f"{_RESOURCE}getCurrentValuesSummary?token={app_token}"
response = requests.get(url_string, timeout=10)
for sensor in response.json():
sid = sensor["sid"]
dev.append(
EfergySensor(
variable[CONF_SENSOR_TYPE],
variable[CONF_TYPE],
app_token,
utc_offset,
variable[CONF_PERIOD],
@ -79,7 +83,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
)
dev.append(
EfergySensor(
variable[CONF_SENSOR_TYPE],
variable[CONF_TYPE],
app_token,
utc_offset,
variable[CONF_PERIOD],