core/homeassistant/components/emoncms/sensor.py

245 lines
8.3 KiB
Python
Raw Normal View History

"""Support for monitoring emoncms feeds."""
from __future__ import annotations
from typing import Any
Emoncms feeds sensor component (#3258) * Add Initial version for emoncms feeds sensor * flake8 test fixes * pylint test fixes * - fix bug with include_feed_id_names not assigning the name to the element in the same postion as found in include_feed_id - a few structure changes to have less nesting (pylint fix) - minor other changes * update .coveragerc * voluptuous fixes: - exclude_feed_id and include_feed_id Exclusive group so that only one (or none) can be specified at once - id must be positive int - exclude_feed_id and include_feed_id must be positive int * Fix comment so it refers to the documentation * use string formatting * Remove outer try * clean up sensors.append calls (break them out for loop) * multiple changes like: - rename config value "include_feed_id" to "include_only_feed_id" - rename config value "include_feed_id_names" to "sensor_names" - renamed config value sensor_names is now a dictionary an can also be used when renamed config value "include_only_feed_id" is not specified - Set default value for scan_interval using the config validation - blank lines between default, 3rd party and own imports - removed homeassistant.util import, it was not needed anymore * fix extended voluptuous schema scan_interval should not be extended to PLATFORM_SCHEMA as it was already in the schema by config_validation helper so i should not add / change it. It was also causing problems reading the value from the config. * Use Home Assistant polling * remove statement that can never happen * Guard clause * Reduce instance variables
2016-09-18 06:34:24 +00:00
import voluptuous as vol
Emoncms feeds sensor component (#3258) * Add Initial version for emoncms feeds sensor * flake8 test fixes * pylint test fixes * - fix bug with include_feed_id_names not assigning the name to the element in the same postion as found in include_feed_id - a few structure changes to have less nesting (pylint fix) - minor other changes * update .coveragerc * voluptuous fixes: - exclude_feed_id and include_feed_id Exclusive group so that only one (or none) can be specified at once - id must be positive int - exclude_feed_id and include_feed_id must be positive int * Fix comment so it refers to the documentation * use string formatting * Remove outer try * clean up sensors.append calls (break them out for loop) * multiple changes like: - rename config value "include_feed_id" to "include_only_feed_id" - rename config value "include_feed_id_names" to "sensor_names" - renamed config value sensor_names is now a dictionary an can also be used when renamed config value "include_only_feed_id" is not specified - Set default value for scan_interval using the config validation - blank lines between default, 3rd party and own imports - removed homeassistant.util import, it was not needed anymore * fix extended voluptuous schema scan_interval should not be extended to PLATFORM_SCHEMA as it was already in the schema by config_validation helper so i should not add / change it. It was also causing problems reading the value from the config. * Use Home Assistant polling * remove statement that can never happen * Guard clause * Reduce instance variables
2016-09-18 06:34:24 +00:00
from homeassistant.components.sensor import (
PLATFORM_SCHEMA as SENSOR_PLATFORM_SCHEMA,
SensorDeviceClass,
SensorEntity,
SensorStateClass,
)
Migrate emoncms to config flow (#121336) * Migrate emoncms to config flow * tests coverage 98% * use runtime_data * Remove pyemoncms bump. * Remove not needed yaml parameters add async_update_data to coordinator * Reduce snapshot size * Remove CONF_UNIT_OF_MEASUREMENT * correct path in emoncms_client mock * Remove init connexion check as done by config_entry_first_refresh since async_update_data catches exceptionand raise UpdateFailed * Remove CONF_EXCLUDE_FEEDID from config flow * Update homeassistant/components/emoncms/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Use options in options flow and common strings * Extend the ConfigEntry type * Define the type explicitely * Add data description in strings.json * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Add test import same yaml conf + corrections * Add test user flow * Use data_description... * Use snapshot_platform in test_sensor * Transfer all fixtures in conftest * Add async_step_choose_feeds to ask flows to user * Test abortion reason in test_flow_import_failure * Add issue when value_template is i yaml conf * make text more expressive in strings.json * Add issue when no feed imported during migration. * Update tests/components/emoncms/test_config_flow.py * Update tests/components/emoncms/test_config_flow.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-09-03 15:21:13 +00:00
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
Emoncms feeds sensor component (#3258) * Add Initial version for emoncms feeds sensor * flake8 test fixes * pylint test fixes * - fix bug with include_feed_id_names not assigning the name to the element in the same postion as found in include_feed_id - a few structure changes to have less nesting (pylint fix) - minor other changes * update .coveragerc * voluptuous fixes: - exclude_feed_id and include_feed_id Exclusive group so that only one (or none) can be specified at once - id must be positive int - exclude_feed_id and include_feed_id must be positive int * Fix comment so it refers to the documentation * use string formatting * Remove outer try * clean up sensors.append calls (break them out for loop) * multiple changes like: - rename config value "include_feed_id" to "include_only_feed_id" - rename config value "include_feed_id_names" to "sensor_names" - renamed config value sensor_names is now a dictionary an can also be used when renamed config value "include_only_feed_id" is not specified - Set default value for scan_interval using the config validation - blank lines between default, 3rd party and own imports - removed homeassistant.util import, it was not needed anymore * fix extended voluptuous schema scan_interval should not be extended to PLATFORM_SCHEMA as it was already in the schema by config_validation helper so i should not add / change it. It was also causing problems reading the value from the config. * Use Home Assistant polling * remove statement that can never happen * Guard clause * Reduce instance variables
2016-09-18 06:34:24 +00:00
from homeassistant.const import (
2019-07-31 19:25:30 +00:00
CONF_API_KEY,
CONF_ID,
CONF_UNIT_OF_MEASUREMENT,
CONF_URL,
CONF_VALUE_TEMPLATE,
UnitOfPower,
2019-07-31 19:25:30 +00:00
)
Migrate emoncms to config flow (#121336) * Migrate emoncms to config flow * tests coverage 98% * use runtime_data * Remove pyemoncms bump. * Remove not needed yaml parameters add async_update_data to coordinator * Reduce snapshot size * Remove CONF_UNIT_OF_MEASUREMENT * correct path in emoncms_client mock * Remove init connexion check as done by config_entry_first_refresh since async_update_data catches exceptionand raise UpdateFailed * Remove CONF_EXCLUDE_FEEDID from config flow * Update homeassistant/components/emoncms/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Use options in options flow and common strings * Extend the ConfigEntry type * Define the type explicitely * Add data description in strings.json * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Add test import same yaml conf + corrections * Add test user flow * Use data_description... * Use snapshot_platform in test_sensor * Transfer all fixtures in conftest * Add async_step_choose_feeds to ask flows to user * Test abortion reason in test_flow_import_failure * Add issue when value_template is i yaml conf * make text more expressive in strings.json * Add issue when no feed imported during migration. * Update tests/components/emoncms/test_config_flow.py * Update tests/components/emoncms/test_config_flow.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-09-03 15:21:13 +00:00
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant, callback
from homeassistant.data_entry_flow import FlowResultType
Emoncms feeds sensor component (#3258) * Add Initial version for emoncms feeds sensor * flake8 test fixes * pylint test fixes * - fix bug with include_feed_id_names not assigning the name to the element in the same postion as found in include_feed_id - a few structure changes to have less nesting (pylint fix) - minor other changes * update .coveragerc * voluptuous fixes: - exclude_feed_id and include_feed_id Exclusive group so that only one (or none) can be specified at once - id must be positive int - exclude_feed_id and include_feed_id must be positive int * Fix comment so it refers to the documentation * use string formatting * Remove outer try * clean up sensors.append calls (break them out for loop) * multiple changes like: - rename config value "include_feed_id" to "include_only_feed_id" - rename config value "include_feed_id_names" to "sensor_names" - renamed config value sensor_names is now a dictionary an can also be used when renamed config value "include_only_feed_id" is not specified - Set default value for scan_interval using the config validation - blank lines between default, 3rd party and own imports - removed homeassistant.util import, it was not needed anymore * fix extended voluptuous schema scan_interval should not be extended to PLATFORM_SCHEMA as it was already in the schema by config_validation helper so i should not add / change it. It was also causing problems reading the value from the config. * Use Home Assistant polling * remove statement that can never happen * Guard clause * Reduce instance variables
2016-09-18 06:34:24 +00:00
from homeassistant.helpers import template
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Migrate emoncms to config flow (#121336) * Migrate emoncms to config flow * tests coverage 98% * use runtime_data * Remove pyemoncms bump. * Remove not needed yaml parameters add async_update_data to coordinator * Reduce snapshot size * Remove CONF_UNIT_OF_MEASUREMENT * correct path in emoncms_client mock * Remove init connexion check as done by config_entry_first_refresh since async_update_data catches exceptionand raise UpdateFailed * Remove CONF_EXCLUDE_FEEDID from config flow * Update homeassistant/components/emoncms/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Use options in options flow and common strings * Extend the ConfigEntry type * Define the type explicitely * Add data description in strings.json * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Add test import same yaml conf + corrections * Add test user flow * Use data_description... * Use snapshot_platform in test_sensor * Transfer all fixtures in conftest * Add async_step_choose_feeds to ask flows to user * Test abortion reason in test_flow_import_failure * Add issue when value_template is i yaml conf * make text more expressive in strings.json * Add issue when no feed imported during migration. * Update tests/components/emoncms/test_config_flow.py * Update tests/components/emoncms/test_config_flow.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-09-03 15:21:13 +00:00
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
2024-06-22 10:41:54 +00:00
from homeassistant.helpers.update_coordinator import CoordinatorEntity
Migrate emoncms to config flow (#121336) * Migrate emoncms to config flow * tests coverage 98% * use runtime_data * Remove pyemoncms bump. * Remove not needed yaml parameters add async_update_data to coordinator * Reduce snapshot size * Remove CONF_UNIT_OF_MEASUREMENT * correct path in emoncms_client mock * Remove init connexion check as done by config_entry_first_refresh since async_update_data catches exceptionand raise UpdateFailed * Remove CONF_EXCLUDE_FEEDID from config flow * Update homeassistant/components/emoncms/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Use options in options flow and common strings * Extend the ConfigEntry type * Define the type explicitely * Add data description in strings.json * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Add test import same yaml conf + corrections * Add test user flow * Use data_description... * Use snapshot_platform in test_sensor * Transfer all fixtures in conftest * Add async_step_choose_feeds to ask flows to user * Test abortion reason in test_flow_import_failure * Add issue when value_template is i yaml conf * make text more expressive in strings.json * Add issue when no feed imported during migration. * Update tests/components/emoncms/test_config_flow.py * Update tests/components/emoncms/test_config_flow.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-09-03 15:21:13 +00:00
from .config_flow import sensor_name
from .const import (
CONF_EXCLUDE_FEEDID,
CONF_ONLY_INCLUDE_FEEDID,
DOMAIN,
FEED_ID,
FEED_NAME,
FEED_TAG,
)
2024-06-22 10:41:54 +00:00
from .coordinator import EmoncmsCoordinator
Emoncms feeds sensor component (#3258) * Add Initial version for emoncms feeds sensor * flake8 test fixes * pylint test fixes * - fix bug with include_feed_id_names not assigning the name to the element in the same postion as found in include_feed_id - a few structure changes to have less nesting (pylint fix) - minor other changes * update .coveragerc * voluptuous fixes: - exclude_feed_id and include_feed_id Exclusive group so that only one (or none) can be specified at once - id must be positive int - exclude_feed_id and include_feed_id must be positive int * Fix comment so it refers to the documentation * use string formatting * Remove outer try * clean up sensors.append calls (break them out for loop) * multiple changes like: - rename config value "include_feed_id" to "include_only_feed_id" - rename config value "include_feed_id_names" to "sensor_names" - renamed config value sensor_names is now a dictionary an can also be used when renamed config value "include_only_feed_id" is not specified - Set default value for scan_interval using the config validation - blank lines between default, 3rd party and own imports - removed homeassistant.util import, it was not needed anymore * fix extended voluptuous schema scan_interval should not be extended to PLATFORM_SCHEMA as it was already in the schema by config_validation helper so i should not add / change it. It was also causing problems reading the value from the config. * Use Home Assistant polling * remove statement that can never happen * Guard clause * Reduce instance variables
2016-09-18 06:34:24 +00:00
2019-07-31 19:25:30 +00:00
ATTR_FEEDID = "FeedId"
ATTR_FEEDNAME = "FeedName"
ATTR_LASTUPDATETIME = "LastUpdated"
ATTR_LASTUPDATETIMESTR = "LastUpdatedStr"
ATTR_SIZE = "Size"
ATTR_TAG = "Tag"
ATTR_USERID = "UserId"
CONF_SENSOR_NAMES = "sensor_names"
Emoncms feeds sensor component (#3258) * Add Initial version for emoncms feeds sensor * flake8 test fixes * pylint test fixes * - fix bug with include_feed_id_names not assigning the name to the element in the same postion as found in include_feed_id - a few structure changes to have less nesting (pylint fix) - minor other changes * update .coveragerc * voluptuous fixes: - exclude_feed_id and include_feed_id Exclusive group so that only one (or none) can be specified at once - id must be positive int - exclude_feed_id and include_feed_id must be positive int * Fix comment so it refers to the documentation * use string formatting * Remove outer try * clean up sensors.append calls (break them out for loop) * multiple changes like: - rename config value "include_feed_id" to "include_only_feed_id" - rename config value "include_feed_id_names" to "sensor_names" - renamed config value sensor_names is now a dictionary an can also be used when renamed config value "include_only_feed_id" is not specified - Set default value for scan_interval using the config validation - blank lines between default, 3rd party and own imports - removed homeassistant.util import, it was not needed anymore * fix extended voluptuous schema scan_interval should not be extended to PLATFORM_SCHEMA as it was already in the schema by config_validation helper so i should not add / change it. It was also causing problems reading the value from the config. * Use Home Assistant polling * remove statement that can never happen * Guard clause * Reduce instance variables
2016-09-18 06:34:24 +00:00
DECIMALS = 2
DEFAULT_UNIT = UnitOfPower.WATT
Emoncms feeds sensor component (#3258) * Add Initial version for emoncms feeds sensor * flake8 test fixes * pylint test fixes * - fix bug with include_feed_id_names not assigning the name to the element in the same postion as found in include_feed_id - a few structure changes to have less nesting (pylint fix) - minor other changes * update .coveragerc * voluptuous fixes: - exclude_feed_id and include_feed_id Exclusive group so that only one (or none) can be specified at once - id must be positive int - exclude_feed_id and include_feed_id must be positive int * Fix comment so it refers to the documentation * use string formatting * Remove outer try * clean up sensors.append calls (break them out for loop) * multiple changes like: - rename config value "include_feed_id" to "include_only_feed_id" - rename config value "include_feed_id_names" to "sensor_names" - renamed config value sensor_names is now a dictionary an can also be used when renamed config value "include_only_feed_id" is not specified - Set default value for scan_interval using the config validation - blank lines between default, 3rd party and own imports - removed homeassistant.util import, it was not needed anymore * fix extended voluptuous schema scan_interval should not be extended to PLATFORM_SCHEMA as it was already in the schema by config_validation helper so i should not add / change it. It was also causing problems reading the value from the config. * Use Home Assistant polling * remove statement that can never happen * Guard clause * Reduce instance variables
2016-09-18 06:34:24 +00:00
2019-07-31 19:25:30 +00:00
ONLY_INCL_EXCL_NONE = "only_include_exclude_or_none"
PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend(
2019-07-31 19:25:30 +00:00
{
vol.Required(CONF_API_KEY): cv.string,
vol.Required(CONF_URL): cv.string,
vol.Required(CONF_ID): cv.positive_int,
vol.Exclusive(CONF_ONLY_INCLUDE_FEEDID, ONLY_INCL_EXCL_NONE): vol.All(
cv.ensure_list, [cv.positive_int]
),
vol.Exclusive(CONF_EXCLUDE_FEEDID, ONLY_INCL_EXCL_NONE): vol.All(
cv.ensure_list, [cv.positive_int]
),
vol.Optional(CONF_SENSOR_NAMES): vol.All(
{cv.positive_int: vol.All(cv.string, vol.Length(min=1))}
),
vol.Optional(CONF_VALUE_TEMPLATE): cv.template,
vol.Optional(CONF_UNIT_OF_MEASUREMENT, default=DEFAULT_UNIT): cv.string,
}
)
Emoncms feeds sensor component (#3258) * Add Initial version for emoncms feeds sensor * flake8 test fixes * pylint test fixes * - fix bug with include_feed_id_names not assigning the name to the element in the same postion as found in include_feed_id - a few structure changes to have less nesting (pylint fix) - minor other changes * update .coveragerc * voluptuous fixes: - exclude_feed_id and include_feed_id Exclusive group so that only one (or none) can be specified at once - id must be positive int - exclude_feed_id and include_feed_id must be positive int * Fix comment so it refers to the documentation * use string formatting * Remove outer try * clean up sensors.append calls (break them out for loop) * multiple changes like: - rename config value "include_feed_id" to "include_only_feed_id" - rename config value "include_feed_id_names" to "sensor_names" - renamed config value sensor_names is now a dictionary an can also be used when renamed config value "include_only_feed_id" is not specified - Set default value for scan_interval using the config validation - blank lines between default, 3rd party and own imports - removed homeassistant.util import, it was not needed anymore * fix extended voluptuous schema scan_interval should not be extended to PLATFORM_SCHEMA as it was already in the schema by config_validation helper so i should not add / change it. It was also causing problems reading the value from the config. * Use Home Assistant polling * remove statement that can never happen * Guard clause * Reduce instance variables
2016-09-18 06:34:24 +00:00
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
Migrate emoncms to config flow (#121336) * Migrate emoncms to config flow * tests coverage 98% * use runtime_data * Remove pyemoncms bump. * Remove not needed yaml parameters add async_update_data to coordinator * Reduce snapshot size * Remove CONF_UNIT_OF_MEASUREMENT * correct path in emoncms_client mock * Remove init connexion check as done by config_entry_first_refresh since async_update_data catches exceptionand raise UpdateFailed * Remove CONF_EXCLUDE_FEEDID from config flow * Update homeassistant/components/emoncms/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Use options in options flow and common strings * Extend the ConfigEntry type * Define the type explicitely * Add data description in strings.json * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Add test import same yaml conf + corrections * Add test user flow * Use data_description... * Use snapshot_platform in test_sensor * Transfer all fixtures in conftest * Add async_step_choose_feeds to ask flows to user * Test abortion reason in test_flow_import_failure * Add issue when value_template is i yaml conf * make text more expressive in strings.json * Add issue when no feed imported during migration. * Update tests/components/emoncms/test_config_flow.py * Update tests/components/emoncms/test_config_flow.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-09-03 15:21:13 +00:00
"""Import config from yaml."""
if CONF_VALUE_TEMPLATE in config:
async_create_issue(
hass,
DOMAIN,
f"remove_{CONF_VALUE_TEMPLATE}_{DOMAIN}",
is_fixable=False,
issue_domain=DOMAIN,
severity=IssueSeverity.ERROR,
translation_key=f"remove_{CONF_VALUE_TEMPLATE}",
translation_placeholders={
"domain": DOMAIN,
"parameter": CONF_VALUE_TEMPLATE,
},
)
return
if CONF_ONLY_INCLUDE_FEEDID not in config:
async_create_issue(
hass,
DOMAIN,
f"missing_{CONF_ONLY_INCLUDE_FEEDID}_{DOMAIN}",
is_fixable=False,
issue_domain=DOMAIN,
severity=IssueSeverity.WARNING,
translation_key=f"missing_{CONF_ONLY_INCLUDE_FEEDID}",
translation_placeholders={
"domain": DOMAIN,
},
)
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data=config
)
if (
result.get("type") == FlowResultType.CREATE_ENTRY
or result.get("reason") == "already_configured"
):
async_create_issue(
hass,
HOMEASSISTANT_DOMAIN,
f"deprecated_yaml_{DOMAIN}",
is_fixable=False,
issue_domain=DOMAIN,
breaks_in_ha_version="2025.3.0",
severity=IssueSeverity.WARNING,
translation_key="deprecated_yaml",
translation_placeholders={
"domain": DOMAIN,
"integration_title": "emoncms",
},
)
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the emoncms sensors."""
name = sensor_name(entry.data[CONF_URL])
exclude_feeds = entry.data.get(CONF_EXCLUDE_FEEDID)
include_only_feeds = entry.options.get(
CONF_ONLY_INCLUDE_FEEDID, entry.data.get(CONF_ONLY_INCLUDE_FEEDID)
)
Emoncms feeds sensor component (#3258) * Add Initial version for emoncms feeds sensor * flake8 test fixes * pylint test fixes * - fix bug with include_feed_id_names not assigning the name to the element in the same postion as found in include_feed_id - a few structure changes to have less nesting (pylint fix) - minor other changes * update .coveragerc * voluptuous fixes: - exclude_feed_id and include_feed_id Exclusive group so that only one (or none) can be specified at once - id must be positive int - exclude_feed_id and include_feed_id must be positive int * Fix comment so it refers to the documentation * use string formatting * Remove outer try * clean up sensors.append calls (break them out for loop) * multiple changes like: - rename config value "include_feed_id" to "include_only_feed_id" - rename config value "include_feed_id_names" to "sensor_names" - renamed config value sensor_names is now a dictionary an can also be used when renamed config value "include_only_feed_id" is not specified - Set default value for scan_interval using the config validation - blank lines between default, 3rd party and own imports - removed homeassistant.util import, it was not needed anymore * fix extended voluptuous schema scan_interval should not be extended to PLATFORM_SCHEMA as it was already in the schema by config_validation helper so i should not add / change it. It was also causing problems reading the value from the config. * Use Home Assistant polling * remove statement that can never happen * Guard clause * Reduce instance variables
2016-09-18 06:34:24 +00:00
Migrate emoncms to config flow (#121336) * Migrate emoncms to config flow * tests coverage 98% * use runtime_data * Remove pyemoncms bump. * Remove not needed yaml parameters add async_update_data to coordinator * Reduce snapshot size * Remove CONF_UNIT_OF_MEASUREMENT * correct path in emoncms_client mock * Remove init connexion check as done by config_entry_first_refresh since async_update_data catches exceptionand raise UpdateFailed * Remove CONF_EXCLUDE_FEEDID from config flow * Update homeassistant/components/emoncms/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Use options in options flow and common strings * Extend the ConfigEntry type * Define the type explicitely * Add data description in strings.json * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Add test import same yaml conf + corrections * Add test user flow * Use data_description... * Use snapshot_platform in test_sensor * Transfer all fixtures in conftest * Add async_step_choose_feeds to ask flows to user * Test abortion reason in test_flow_import_failure * Add issue when value_template is i yaml conf * make text more expressive in strings.json * Add issue when no feed imported during migration. * Update tests/components/emoncms/test_config_flow.py * Update tests/components/emoncms/test_config_flow.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-09-03 15:21:13 +00:00
if exclude_feeds is None and include_only_feeds is None:
return
coordinator = entry.runtime_data
2024-06-22 10:41:54 +00:00
elems = coordinator.data
if not elems:
return
Emoncms feeds sensor component (#3258) * Add Initial version for emoncms feeds sensor * flake8 test fixes * pylint test fixes * - fix bug with include_feed_id_names not assigning the name to the element in the same postion as found in include_feed_id - a few structure changes to have less nesting (pylint fix) - minor other changes * update .coveragerc * voluptuous fixes: - exclude_feed_id and include_feed_id Exclusive group so that only one (or none) can be specified at once - id must be positive int - exclude_feed_id and include_feed_id must be positive int * Fix comment so it refers to the documentation * use string formatting * Remove outer try * clean up sensors.append calls (break them out for loop) * multiple changes like: - rename config value "include_feed_id" to "include_only_feed_id" - rename config value "include_feed_id_names" to "sensor_names" - renamed config value sensor_names is now a dictionary an can also be used when renamed config value "include_only_feed_id" is not specified - Set default value for scan_interval using the config validation - blank lines between default, 3rd party and own imports - removed homeassistant.util import, it was not needed anymore * fix extended voluptuous schema scan_interval should not be extended to PLATFORM_SCHEMA as it was already in the schema by config_validation helper so i should not add / change it. It was also causing problems reading the value from the config. * Use Home Assistant polling * remove statement that can never happen * Guard clause * Reduce instance variables
2016-09-18 06:34:24 +00:00
2024-06-22 10:41:54 +00:00
sensors: list[EmonCmsSensor] = []
Emoncms feeds sensor component (#3258) * Add Initial version for emoncms feeds sensor * flake8 test fixes * pylint test fixes * - fix bug with include_feed_id_names not assigning the name to the element in the same postion as found in include_feed_id - a few structure changes to have less nesting (pylint fix) - minor other changes * update .coveragerc * voluptuous fixes: - exclude_feed_id and include_feed_id Exclusive group so that only one (or none) can be specified at once - id must be positive int - exclude_feed_id and include_feed_id must be positive int * Fix comment so it refers to the documentation * use string formatting * Remove outer try * clean up sensors.append calls (break them out for loop) * multiple changes like: - rename config value "include_feed_id" to "include_only_feed_id" - rename config value "include_feed_id_names" to "sensor_names" - renamed config value sensor_names is now a dictionary an can also be used when renamed config value "include_only_feed_id" is not specified - Set default value for scan_interval using the config validation - blank lines between default, 3rd party and own imports - removed homeassistant.util import, it was not needed anymore * fix extended voluptuous schema scan_interval should not be extended to PLATFORM_SCHEMA as it was already in the schema by config_validation helper so i should not add / change it. It was also causing problems reading the value from the config. * Use Home Assistant polling * remove statement that can never happen * Guard clause * Reduce instance variables
2016-09-18 06:34:24 +00:00
2024-06-22 10:41:54 +00:00
for idx, elem in enumerate(elems):
Migrate emoncms to config flow (#121336) * Migrate emoncms to config flow * tests coverage 98% * use runtime_data * Remove pyemoncms bump. * Remove not needed yaml parameters add async_update_data to coordinator * Reduce snapshot size * Remove CONF_UNIT_OF_MEASUREMENT * correct path in emoncms_client mock * Remove init connexion check as done by config_entry_first_refresh since async_update_data catches exceptionand raise UpdateFailed * Remove CONF_EXCLUDE_FEEDID from config flow * Update homeassistant/components/emoncms/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Use options in options flow and common strings * Extend the ConfigEntry type * Define the type explicitely * Add data description in strings.json * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Add test import same yaml conf + corrections * Add test user flow * Use data_description... * Use snapshot_platform in test_sensor * Transfer all fixtures in conftest * Add async_step_choose_feeds to ask flows to user * Test abortion reason in test_flow_import_failure * Add issue when value_template is i yaml conf * make text more expressive in strings.json * Add issue when no feed imported during migration. * Update tests/components/emoncms/test_config_flow.py * Update tests/components/emoncms/test_config_flow.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-09-03 15:21:13 +00:00
if include_only_feeds is not None and elem[FEED_ID] not in include_only_feeds:
continue
Emoncms feeds sensor component (#3258) * Add Initial version for emoncms feeds sensor * flake8 test fixes * pylint test fixes * - fix bug with include_feed_id_names not assigning the name to the element in the same postion as found in include_feed_id - a few structure changes to have less nesting (pylint fix) - minor other changes * update .coveragerc * voluptuous fixes: - exclude_feed_id and include_feed_id Exclusive group so that only one (or none) can be specified at once - id must be positive int - exclude_feed_id and include_feed_id must be positive int * Fix comment so it refers to the documentation * use string formatting * Remove outer try * clean up sensors.append calls (break them out for loop) * multiple changes like: - rename config value "include_feed_id" to "include_only_feed_id" - rename config value "include_feed_id_names" to "sensor_names" - renamed config value sensor_names is now a dictionary an can also be used when renamed config value "include_only_feed_id" is not specified - Set default value for scan_interval using the config validation - blank lines between default, 3rd party and own imports - removed homeassistant.util import, it was not needed anymore * fix extended voluptuous schema scan_interval should not be extended to PLATFORM_SCHEMA as it was already in the schema by config_validation helper so i should not add / change it. It was also causing problems reading the value from the config. * Use Home Assistant polling * remove statement that can never happen * Guard clause * Reduce instance variables
2016-09-18 06:34:24 +00:00
2019-07-31 19:25:30 +00:00
sensors.append(
EmonCmsSensor(
2024-06-22 10:41:54 +00:00
coordinator,
Migrate emoncms to config flow (#121336) * Migrate emoncms to config flow * tests coverage 98% * use runtime_data * Remove pyemoncms bump. * Remove not needed yaml parameters add async_update_data to coordinator * Reduce snapshot size * Remove CONF_UNIT_OF_MEASUREMENT * correct path in emoncms_client mock * Remove init connexion check as done by config_entry_first_refresh since async_update_data catches exceptionand raise UpdateFailed * Remove CONF_EXCLUDE_FEEDID from config flow * Update homeassistant/components/emoncms/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Use options in options flow and common strings * Extend the ConfigEntry type * Define the type explicitely * Add data description in strings.json * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Add test import same yaml conf + corrections * Add test user flow * Use data_description... * Use snapshot_platform in test_sensor * Transfer all fixtures in conftest * Add async_step_choose_feeds to ask flows to user * Test abortion reason in test_flow_import_failure * Add issue when value_template is i yaml conf * make text more expressive in strings.json * Add issue when no feed imported during migration. * Update tests/components/emoncms/test_config_flow.py * Update tests/components/emoncms/test_config_flow.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-09-03 15:21:13 +00:00
entry.entry_id,
elem["unit"],
2019-07-31 19:25:30 +00:00
name,
2024-06-22 10:41:54 +00:00
idx,
2019-07-31 19:25:30 +00:00
)
)
async_add_entities(sensors)
Emoncms feeds sensor component (#3258) * Add Initial version for emoncms feeds sensor * flake8 test fixes * pylint test fixes * - fix bug with include_feed_id_names not assigning the name to the element in the same postion as found in include_feed_id - a few structure changes to have less nesting (pylint fix) - minor other changes * update .coveragerc * voluptuous fixes: - exclude_feed_id and include_feed_id Exclusive group so that only one (or none) can be specified at once - id must be positive int - exclude_feed_id and include_feed_id must be positive int * Fix comment so it refers to the documentation * use string formatting * Remove outer try * clean up sensors.append calls (break them out for loop) * multiple changes like: - rename config value "include_feed_id" to "include_only_feed_id" - rename config value "include_feed_id_names" to "sensor_names" - renamed config value sensor_names is now a dictionary an can also be used when renamed config value "include_only_feed_id" is not specified - Set default value for scan_interval using the config validation - blank lines between default, 3rd party and own imports - removed homeassistant.util import, it was not needed anymore * fix extended voluptuous schema scan_interval should not be extended to PLATFORM_SCHEMA as it was already in the schema by config_validation helper so i should not add / change it. It was also causing problems reading the value from the config. * Use Home Assistant polling * remove statement that can never happen * Guard clause * Reduce instance variables
2016-09-18 06:34:24 +00:00
2024-06-22 10:41:54 +00:00
class EmonCmsSensor(CoordinatorEntity[EmoncmsCoordinator], SensorEntity):
"""Implementation of an Emoncms sensor."""
Emoncms feeds sensor component (#3258) * Add Initial version for emoncms feeds sensor * flake8 test fixes * pylint test fixes * - fix bug with include_feed_id_names not assigning the name to the element in the same postion as found in include_feed_id - a few structure changes to have less nesting (pylint fix) - minor other changes * update .coveragerc * voluptuous fixes: - exclude_feed_id and include_feed_id Exclusive group so that only one (or none) can be specified at once - id must be positive int - exclude_feed_id and include_feed_id must be positive int * Fix comment so it refers to the documentation * use string formatting * Remove outer try * clean up sensors.append calls (break them out for loop) * multiple changes like: - rename config value "include_feed_id" to "include_only_feed_id" - rename config value "include_feed_id_names" to "sensor_names" - renamed config value sensor_names is now a dictionary an can also be used when renamed config value "include_only_feed_id" is not specified - Set default value for scan_interval using the config validation - blank lines between default, 3rd party and own imports - removed homeassistant.util import, it was not needed anymore * fix extended voluptuous schema scan_interval should not be extended to PLATFORM_SCHEMA as it was already in the schema by config_validation helper so i should not add / change it. It was also causing problems reading the value from the config. * Use Home Assistant polling * remove statement that can never happen * Guard clause * Reduce instance variables
2016-09-18 06:34:24 +00:00
2019-07-31 19:25:30 +00:00
def __init__(
self,
2024-06-22 10:41:54 +00:00
coordinator: EmoncmsCoordinator,
Migrate emoncms to config flow (#121336) * Migrate emoncms to config flow * tests coverage 98% * use runtime_data * Remove pyemoncms bump. * Remove not needed yaml parameters add async_update_data to coordinator * Reduce snapshot size * Remove CONF_UNIT_OF_MEASUREMENT * correct path in emoncms_client mock * Remove init connexion check as done by config_entry_first_refresh since async_update_data catches exceptionand raise UpdateFailed * Remove CONF_EXCLUDE_FEEDID from config flow * Update homeassistant/components/emoncms/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Use options in options flow and common strings * Extend the ConfigEntry type * Define the type explicitely * Add data description in strings.json * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Add test import same yaml conf + corrections * Add test user flow * Use data_description... * Use snapshot_platform in test_sensor * Transfer all fixtures in conftest * Add async_step_choose_feeds to ask flows to user * Test abortion reason in test_flow_import_failure * Add issue when value_template is i yaml conf * make text more expressive in strings.json * Add issue when no feed imported during migration. * Update tests/components/emoncms/test_config_flow.py * Update tests/components/emoncms/test_config_flow.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-09-03 15:21:13 +00:00
entry_id: str,
unit_of_measurement: str | None,
Migrate emoncms to config flow (#121336) * Migrate emoncms to config flow * tests coverage 98% * use runtime_data * Remove pyemoncms bump. * Remove not needed yaml parameters add async_update_data to coordinator * Reduce snapshot size * Remove CONF_UNIT_OF_MEASUREMENT * correct path in emoncms_client mock * Remove init connexion check as done by config_entry_first_refresh since async_update_data catches exceptionand raise UpdateFailed * Remove CONF_EXCLUDE_FEEDID from config flow * Update homeassistant/components/emoncms/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Use options in options flow and common strings * Extend the ConfigEntry type * Define the type explicitely * Add data description in strings.json * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Add test import same yaml conf + corrections * Add test user flow * Use data_description... * Use snapshot_platform in test_sensor * Transfer all fixtures in conftest * Add async_step_choose_feeds to ask flows to user * Test abortion reason in test_flow_import_failure * Add issue when value_template is i yaml conf * make text more expressive in strings.json * Add issue when no feed imported during migration. * Update tests/components/emoncms/test_config_flow.py * Update tests/components/emoncms/test_config_flow.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-09-03 15:21:13 +00:00
name: str,
2024-06-22 10:41:54 +00:00
idx: int,
) -> None:
Emoncms feeds sensor component (#3258) * Add Initial version for emoncms feeds sensor * flake8 test fixes * pylint test fixes * - fix bug with include_feed_id_names not assigning the name to the element in the same postion as found in include_feed_id - a few structure changes to have less nesting (pylint fix) - minor other changes * update .coveragerc * voluptuous fixes: - exclude_feed_id and include_feed_id Exclusive group so that only one (or none) can be specified at once - id must be positive int - exclude_feed_id and include_feed_id must be positive int * Fix comment so it refers to the documentation * use string formatting * Remove outer try * clean up sensors.append calls (break them out for loop) * multiple changes like: - rename config value "include_feed_id" to "include_only_feed_id" - rename config value "include_feed_id_names" to "sensor_names" - renamed config value sensor_names is now a dictionary an can also be used when renamed config value "include_only_feed_id" is not specified - Set default value for scan_interval using the config validation - blank lines between default, 3rd party and own imports - removed homeassistant.util import, it was not needed anymore * fix extended voluptuous schema scan_interval should not be extended to PLATFORM_SCHEMA as it was already in the schema by config_validation helper so i should not add / change it. It was also causing problems reading the value from the config. * Use Home Assistant polling * remove statement that can never happen * Guard clause * Reduce instance variables
2016-09-18 06:34:24 +00:00
"""Initialize the sensor."""
2024-06-22 10:41:54 +00:00
super().__init__(coordinator)
self.idx = idx
elem = {}
if self.coordinator.data:
elem = self.coordinator.data[self.idx]
Migrate emoncms to config flow (#121336) * Migrate emoncms to config flow * tests coverage 98% * use runtime_data * Remove pyemoncms bump. * Remove not needed yaml parameters add async_update_data to coordinator * Reduce snapshot size * Remove CONF_UNIT_OF_MEASUREMENT * correct path in emoncms_client mock * Remove init connexion check as done by config_entry_first_refresh since async_update_data catches exceptionand raise UpdateFailed * Remove CONF_EXCLUDE_FEEDID from config flow * Update homeassistant/components/emoncms/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Use options in options flow and common strings * Extend the ConfigEntry type * Define the type explicitely * Add data description in strings.json * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Add test import same yaml conf + corrections * Add test user flow * Use data_description... * Use snapshot_platform in test_sensor * Transfer all fixtures in conftest * Add async_step_choose_feeds to ask flows to user * Test abortion reason in test_flow_import_failure * Add issue when value_template is i yaml conf * make text more expressive in strings.json * Add issue when no feed imported during migration. * Update tests/components/emoncms/test_config_flow.py * Update tests/components/emoncms/test_config_flow.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-09-03 15:21:13 +00:00
self._attr_name = f"{name} {elem[FEED_NAME]}"
self._attr_native_unit_of_measurement = unit_of_measurement
Migrate emoncms to config flow (#121336) * Migrate emoncms to config flow * tests coverage 98% * use runtime_data * Remove pyemoncms bump. * Remove not needed yaml parameters add async_update_data to coordinator * Reduce snapshot size * Remove CONF_UNIT_OF_MEASUREMENT * correct path in emoncms_client mock * Remove init connexion check as done by config_entry_first_refresh since async_update_data catches exceptionand raise UpdateFailed * Remove CONF_EXCLUDE_FEEDID from config flow * Update homeassistant/components/emoncms/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Use options in options flow and common strings * Extend the ConfigEntry type * Define the type explicitely * Add data description in strings.json * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Add test import same yaml conf + corrections * Add test user flow * Use data_description... * Use snapshot_platform in test_sensor * Transfer all fixtures in conftest * Add async_step_choose_feeds to ask flows to user * Test abortion reason in test_flow_import_failure * Add issue when value_template is i yaml conf * make text more expressive in strings.json * Add issue when no feed imported during migration. * Update tests/components/emoncms/test_config_flow.py * Update tests/components/emoncms/test_config_flow.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-09-03 15:21:13 +00:00
self._attr_unique_id = f"{entry_id}-{elem[FEED_ID]}"
if unit_of_measurement in ("kWh", "Wh"):
self._attr_device_class = SensorDeviceClass.ENERGY
self._attr_state_class = SensorStateClass.TOTAL_INCREASING
elif unit_of_measurement == "W":
self._attr_device_class = SensorDeviceClass.POWER
self._attr_state_class = SensorStateClass.MEASUREMENT
elif unit_of_measurement == "V":
self._attr_device_class = SensorDeviceClass.VOLTAGE
self._attr_state_class = SensorStateClass.MEASUREMENT
elif unit_of_measurement == "A":
self._attr_device_class = SensorDeviceClass.CURRENT
self._attr_state_class = SensorStateClass.MEASUREMENT
elif unit_of_measurement == "VA":
self._attr_device_class = SensorDeviceClass.APPARENT_POWER
self._attr_state_class = SensorStateClass.MEASUREMENT
elif unit_of_measurement in ("°C", "°F", "K"):
self._attr_device_class = SensorDeviceClass.TEMPERATURE
self._attr_state_class = SensorStateClass.MEASUREMENT
elif unit_of_measurement == "Hz":
self._attr_device_class = SensorDeviceClass.FREQUENCY
self._attr_state_class = SensorStateClass.MEASUREMENT
elif unit_of_measurement == "hPa":
self._attr_device_class = SensorDeviceClass.PRESSURE
self._attr_state_class = SensorStateClass.MEASUREMENT
self._update_attributes(elem)
def _update_attributes(self, elem: dict[str, Any]) -> None:
"""Update entity attributes."""
self._attr_extra_state_attributes = {
Migrate emoncms to config flow (#121336) * Migrate emoncms to config flow * tests coverage 98% * use runtime_data * Remove pyemoncms bump. * Remove not needed yaml parameters add async_update_data to coordinator * Reduce snapshot size * Remove CONF_UNIT_OF_MEASUREMENT * correct path in emoncms_client mock * Remove init connexion check as done by config_entry_first_refresh since async_update_data catches exceptionand raise UpdateFailed * Remove CONF_EXCLUDE_FEEDID from config flow * Update homeassistant/components/emoncms/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Use options in options flow and common strings * Extend the ConfigEntry type * Define the type explicitely * Add data description in strings.json * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Add test import same yaml conf + corrections * Add test user flow * Use data_description... * Use snapshot_platform in test_sensor * Transfer all fixtures in conftest * Add async_step_choose_feeds to ask flows to user * Test abortion reason in test_flow_import_failure * Add issue when value_template is i yaml conf * make text more expressive in strings.json * Add issue when no feed imported during migration. * Update tests/components/emoncms/test_config_flow.py * Update tests/components/emoncms/test_config_flow.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-09-03 15:21:13 +00:00
ATTR_FEEDID: elem[FEED_ID],
ATTR_TAG: elem[FEED_TAG],
ATTR_FEEDNAME: elem[FEED_NAME],
}
if elem["value"] is not None:
self._attr_extra_state_attributes[ATTR_SIZE] = elem["size"]
self._attr_extra_state_attributes[ATTR_USERID] = elem["userid"]
self._attr_extra_state_attributes[ATTR_LASTUPDATETIME] = elem["time"]
self._attr_extra_state_attributes[ATTR_LASTUPDATETIMESTR] = (
template.timestamp_local(float(elem["time"]))
)
self._attr_native_value = None
Migrate emoncms to config flow (#121336) * Migrate emoncms to config flow * tests coverage 98% * use runtime_data * Remove pyemoncms bump. * Remove not needed yaml parameters add async_update_data to coordinator * Reduce snapshot size * Remove CONF_UNIT_OF_MEASUREMENT * correct path in emoncms_client mock * Remove init connexion check as done by config_entry_first_refresh since async_update_data catches exceptionand raise UpdateFailed * Remove CONF_EXCLUDE_FEEDID from config flow * Update homeassistant/components/emoncms/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/emoncms/strings.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Use options in options flow and common strings * Extend the ConfigEntry type * Define the type explicitely * Add data description in strings.json * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/emoncms/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Add test import same yaml conf + corrections * Add test user flow * Use data_description... * Use snapshot_platform in test_sensor * Transfer all fixtures in conftest * Add async_step_choose_feeds to ask flows to user * Test abortion reason in test_flow_import_failure * Add issue when value_template is i yaml conf * make text more expressive in strings.json * Add issue when no feed imported during migration. * Update tests/components/emoncms/test_config_flow.py * Update tests/components/emoncms/test_config_flow.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-09-03 15:21:13 +00:00
if elem["value"] is not None:
self._attr_native_value = round(float(elem["value"]), DECIMALS)
Emoncms feeds sensor component (#3258) * Add Initial version for emoncms feeds sensor * flake8 test fixes * pylint test fixes * - fix bug with include_feed_id_names not assigning the name to the element in the same postion as found in include_feed_id - a few structure changes to have less nesting (pylint fix) - minor other changes * update .coveragerc * voluptuous fixes: - exclude_feed_id and include_feed_id Exclusive group so that only one (or none) can be specified at once - id must be positive int - exclude_feed_id and include_feed_id must be positive int * Fix comment so it refers to the documentation * use string formatting * Remove outer try * clean up sensors.append calls (break them out for loop) * multiple changes like: - rename config value "include_feed_id" to "include_only_feed_id" - rename config value "include_feed_id_names" to "sensor_names" - renamed config value sensor_names is now a dictionary an can also be used when renamed config value "include_only_feed_id" is not specified - Set default value for scan_interval using the config validation - blank lines between default, 3rd party and own imports - removed homeassistant.util import, it was not needed anymore * fix extended voluptuous schema scan_interval should not be extended to PLATFORM_SCHEMA as it was already in the schema by config_validation helper so i should not add / change it. It was also causing problems reading the value from the config. * Use Home Assistant polling * remove statement that can never happen * Guard clause * Reduce instance variables
2016-09-18 06:34:24 +00:00
2024-06-22 10:41:54 +00:00
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
data = self.coordinator.data
if data:
self._update_attributes(data[self.idx])
super()._handle_coordinator_update()