mirror of
https://github.com/magico13/ha-emporia-vue.git
synced 2026-01-09 20:37:59 -05:00
Show text for enabling extra sensors. Start adding checks for being enabled
This commit is contained in:
@@ -12,7 +12,7 @@ from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
||||
from pyemvue import PyEmVue
|
||||
from pyemvue.device import VueDevice, VueDeviceChannel
|
||||
|
||||
from .const import DOMAIN, VUE_DATA
|
||||
from .const import DOMAIN, VUE_DATA, ENABLE_1S, ENABLE_1M, ENABLE_1D, ENABLE_1MON
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
@@ -20,6 +20,10 @@ CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_EMAIL): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Optional(ENABLE_1S, default=False): cv.boolean,
|
||||
vol.Optional(ENABLE_1M, default=True): cv.boolean,
|
||||
vol.Optional(ENABLE_1D, default=True): cv.boolean,
|
||||
vol.Optional(ENABLE_1MON, default=True): cv.boolean
|
||||
}
|
||||
)
|
||||
},
|
||||
@@ -44,6 +48,10 @@ async def async_setup(hass: HomeAssistant, config: dict):
|
||||
data={
|
||||
CONF_EMAIL: conf[CONF_EMAIL],
|
||||
CONF_PASSWORD: conf[CONF_PASSWORD],
|
||||
ENABLE_1S: conf[ENABLE_1S],
|
||||
ENABLE_1M: conf[ENABLE_1M],
|
||||
ENABLE_1D: conf[ENABLE_1D],
|
||||
ENABLE_1MON: conf[ENABLE_1MON]
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
@@ -7,6 +7,7 @@ from homeassistant import config_entries, core, exceptions
|
||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
||||
|
||||
from .const import DOMAIN # pylint:disable=unused-import
|
||||
from .const import ENABLE_1S, ENABLE_1M, ENABLE_1D, ENABLE_1MON
|
||||
|
||||
from pyemvue import PyEmVue
|
||||
|
||||
@@ -16,9 +17,10 @@ DATA_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_EMAIL): str,
|
||||
vol.Required(CONF_PASSWORD): str,
|
||||
vol.Optional("enable_1s", default=False): bool,
|
||||
vol.Optional("enable_1d", default=True): bool,
|
||||
vol.Optional("enable_1mon", default=True): bool
|
||||
vol.Optional(ENABLE_1S, default=False): bool,
|
||||
vol.Optional(ENABLE_1M, default=True): bool,
|
||||
vol.Optional(ENABLE_1D, default=True): bool,
|
||||
vol.Optional(ENABLE_1MON, default=True): bool
|
||||
}
|
||||
)
|
||||
|
||||
@@ -56,9 +58,10 @@ async def validate_input(hass: core.HomeAssistant, data):
|
||||
return {
|
||||
"title": f"Customer {hub.vue.customer.customer_gid}",
|
||||
"gid": f"{hub.vue.customer.customer_gid}",
|
||||
"enable_1s": data["enable_1s"],
|
||||
"enable_1d": data["enable_1d"],
|
||||
"enable_1mon": data["enable_1mon"]
|
||||
ENABLE_1S: data[ENABLE_1S],
|
||||
ENABLE_1M: data[ENABLE_1M],
|
||||
ENABLE_1D: data[ENABLE_1D],
|
||||
ENABLE_1MON: data[ENABLE_1MON]
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
"""Constants for the Emporia Vue integration."""
|
||||
|
||||
DOMAIN = "emporia_vue"
|
||||
VUE_DATA = "vue_data"
|
||||
VUE_DATA = "vue_data"
|
||||
ENABLE_1S = "enable_1s"
|
||||
ENABLE_1M = "enable_1m"
|
||||
ENABLE_1D = "enable_1d"
|
||||
ENABLE_1MON = "enable_1mon"
|
||||
@@ -93,26 +93,29 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
update_interval=timedelta(seconds=60),
|
||||
)
|
||||
|
||||
coordinator_1s = DataUpdateCoordinator(
|
||||
hass,
|
||||
_LOGGER,
|
||||
# Name of the data. For logging purposes.
|
||||
name='sensor1s',
|
||||
update_method=async_update_data_1second,
|
||||
# Polling interval. Will only be polled if there are subscribers.
|
||||
update_interval=timedelta(seconds=1),
|
||||
)
|
||||
if config_entry[ENABLE_1S]:
|
||||
coordinator_1s = DataUpdateCoordinator(
|
||||
hass,
|
||||
_LOGGER,
|
||||
# Name of the data. For logging purposes.
|
||||
name='sensor1s',
|
||||
update_method=async_update_data_1second,
|
||||
# Polling interval. Will only be polled if there are subscribers.
|
||||
update_interval=timedelta(seconds=1),
|
||||
)
|
||||
await coordinator_1s.async_refresh()
|
||||
async_add_entities(
|
||||
CurrentVuePowerSensor(coordinator_1s, id) for idx, id in enumerate(coordinator_1s.data)
|
||||
)
|
||||
|
||||
#todo: add checks for other scales enabled
|
||||
await coordinator_1min.async_refresh()
|
||||
await coordinator_1s.async_refresh()
|
||||
|
||||
|
||||
async_add_entities(
|
||||
CurrentVuePowerSensor(coordinator_1min, id) for idx, id in enumerate(coordinator_1min.data)
|
||||
)
|
||||
|
||||
async_add_entities(
|
||||
CurrentVuePowerSensor(coordinator_1s, id) for idx, id in enumerate(coordinator_1s.data)
|
||||
)
|
||||
|
||||
|
||||
class CurrentVuePowerSensor(CoordinatorEntity, Entity):
|
||||
"""Representation of a Vue Sensor's current power."""
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
"user": {
|
||||
"data": {
|
||||
"email": "[%key:common::config_flow::data::email%]",
|
||||
"password": "[%key:common::config_flow::data::password%]"
|
||||
"password": "[%key:common::config_flow::data::password%]",
|
||||
"enable_1s": "One Second Sensor",
|
||||
"enable_1m": "One Minute Sensor",
|
||||
"enable_1d": "One Day Sensor",
|
||||
"enable_1mon": "One Month Sensor"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -12,7 +12,11 @@
|
||||
"user": {
|
||||
"data": {
|
||||
"email": "Email",
|
||||
"password": "Password"
|
||||
"password": "Password",
|
||||
"enable_1s": "One Second Sensor",
|
||||
"enable_1m": "One Minute Sensor",
|
||||
"enable_1d": "One Day Sensor",
|
||||
"enable_1mon": "One Month Sensor"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user