Add and use currency constants (#40113)
This commit is contained in:
parent
90f5b178ef
commit
000d2047fb
7 changed files with 38 additions and 19 deletions
|
@ -1,6 +1,7 @@
|
|||
"""Definitions for DSMR Reader sensors added to MQTT."""
|
||||
|
||||
from homeassistant.const import (
|
||||
CURRENCY_EURO,
|
||||
ELECTRICAL_CURRENT_AMPERE,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
VOLT,
|
||||
|
@ -166,17 +167,17 @@ DEFINITIONS = {
|
|||
"dsmr/day-consumption/electricity1_cost": {
|
||||
"name": "Low tariff cost",
|
||||
"icon": "mdi:currency-eur",
|
||||
"unit": "€",
|
||||
"unit": CURRENCY_EURO,
|
||||
},
|
||||
"dsmr/day-consumption/electricity2_cost": {
|
||||
"name": "High tariff cost",
|
||||
"icon": "mdi:currency-eur",
|
||||
"unit": "€",
|
||||
"unit": CURRENCY_EURO,
|
||||
},
|
||||
"dsmr/day-consumption/electricity_cost_merged": {
|
||||
"name": "Power total cost",
|
||||
"icon": "mdi:currency-eur",
|
||||
"unit": "€",
|
||||
"unit": CURRENCY_EURO,
|
||||
},
|
||||
"dsmr/day-consumption/gas": {
|
||||
"name": "Gas usage",
|
||||
|
@ -186,37 +187,37 @@ DEFINITIONS = {
|
|||
"dsmr/day-consumption/gas_cost": {
|
||||
"name": "Gas cost",
|
||||
"icon": "mdi:currency-eur",
|
||||
"unit": "€",
|
||||
"unit": CURRENCY_EURO,
|
||||
},
|
||||
"dsmr/day-consumption/total_cost": {
|
||||
"name": "Total cost",
|
||||
"icon": "mdi:currency-eur",
|
||||
"unit": "€",
|
||||
"unit": CURRENCY_EURO,
|
||||
},
|
||||
"dsmr/day-consumption/energy_supplier_price_electricity_delivered_1": {
|
||||
"name": "Low tariff delivered price",
|
||||
"icon": "mdi:currency-eur",
|
||||
"unit": "€",
|
||||
"unit": CURRENCY_EURO,
|
||||
},
|
||||
"dsmr/day-consumption/energy_supplier_price_electricity_delivered_2": {
|
||||
"name": "High tariff delivered price",
|
||||
"icon": "mdi:currency-eur",
|
||||
"unit": "€",
|
||||
"unit": CURRENCY_EURO,
|
||||
},
|
||||
"dsmr/day-consumption/energy_supplier_price_electricity_returned_1": {
|
||||
"name": "Low tariff returned price",
|
||||
"icon": "mdi:currency-eur",
|
||||
"unit": "€",
|
||||
"unit": CURRENCY_EURO,
|
||||
},
|
||||
"dsmr/day-consumption/energy_supplier_price_electricity_returned_2": {
|
||||
"name": "High tariff returned price",
|
||||
"icon": "mdi:currency-eur",
|
||||
"unit": "€",
|
||||
"unit": CURRENCY_EURO,
|
||||
},
|
||||
"dsmr/day-consumption/energy_supplier_price_gas": {
|
||||
"name": "Gas price",
|
||||
"icon": "mdi:currency-eur",
|
||||
"unit": "€",
|
||||
"unit": CURRENCY_EURO,
|
||||
},
|
||||
"dsmr/meter-stats/dsmr_version": {
|
||||
"name": "DSMR version",
|
||||
|
|
|
@ -12,6 +12,7 @@ from homeassistant.const import (
|
|||
CONF_NAME,
|
||||
CONF_PASSWORD,
|
||||
CONF_USERNAME,
|
||||
CURRENCY_EURO,
|
||||
DEVICE_CLASS_BATTERY,
|
||||
DEVICE_CLASS_CURRENT,
|
||||
DEVICE_CLASS_ENERGY,
|
||||
|
@ -39,8 +40,8 @@ SCAN_INTERVAL = datetime.timedelta(minutes=5)
|
|||
# Sensor type order is: Sensor name, Unit of measurement, api data name, additional options
|
||||
|
||||
TOTAL_SENSOR_TYPES = {
|
||||
"total_money_today": ("Total money today", "€", "plantMoneyText", {}),
|
||||
"total_money_total": ("Money lifetime", "€", "totalMoneyText", {}),
|
||||
"total_money_today": ("Total money today", CURRENCY_EURO, "plantMoneyText", {}),
|
||||
"total_money_total": ("Money lifetime", CURRENCY_EURO, "totalMoneyText", {}),
|
||||
"total_energy_today": (
|
||||
"Energy Today",
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
|
|
|
@ -46,6 +46,7 @@ from homeassistant.components.switch import DOMAIN as SWITCH
|
|||
from homeassistant.const import (
|
||||
AREA_SQUARE_METERS,
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
CURRENCY_DOLLAR,
|
||||
DEGREE,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
FREQUENCY_HERTZ,
|
||||
|
@ -397,7 +398,7 @@ UOM_FRIENDLY_NAME = {
|
|||
UOM_8_BIT_RANGE: "", # Range 0-255, no unit.
|
||||
UOM_DOUBLE_TEMP: UOM_DOUBLE_TEMP,
|
||||
"102": "kWs",
|
||||
"103": "$",
|
||||
"103": CURRENCY_DOLLAR,
|
||||
"104": "¢",
|
||||
"105": LENGTH_INCHES,
|
||||
"106": f"mm/{TIME_DAYS}",
|
||||
|
|
|
@ -6,7 +6,7 @@ from typing import Optional
|
|||
from aiopvpc import PVPCData
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import CONF_NAME, ENERGY_KILO_WATT_HOUR
|
||||
from homeassistant.const import CONF_NAME, CURRENCY_EURO, ENERGY_KILO_WATT_HOUR
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.event import async_call_later, async_track_time_change
|
||||
|
@ -19,7 +19,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
ATTR_PRICE = "price"
|
||||
ICON = "mdi:currency-eur"
|
||||
UNIT = f"€/{ENERGY_KILO_WATT_HOUR}"
|
||||
UNIT = f"{CURRENCY_EURO}/{ENERGY_KILO_WATT_HOUR}"
|
||||
|
||||
_DEFAULT_TIMEOUT = 10
|
||||
|
||||
|
|
|
@ -2,7 +2,12 @@
|
|||
|
||||
import logging
|
||||
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, ATTR_LATITUDE, ATTR_LONGITUDE
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
ATTR_LATITUDE,
|
||||
ATTR_LONGITUDE,
|
||||
CURRENCY_EURO,
|
||||
)
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
|
@ -106,7 +111,7 @@ class FuelPriceSensor(CoordinatorEntity):
|
|||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return unit of measurement."""
|
||||
return "€"
|
||||
return CURRENCY_EURO
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
|
|
@ -380,6 +380,10 @@ ELECTRICAL_VOLT_AMPERE = f"{VOLT}{ELECTRICAL_CURRENT_AMPERE}"
|
|||
# Degree units
|
||||
DEGREE = "°"
|
||||
|
||||
# Currency units
|
||||
CURRENCY_EURO = "€"
|
||||
CURRENCY_DOLLAR = "$"
|
||||
|
||||
# Temperature units
|
||||
TEMP_CELSIUS = f"{DEGREE}C"
|
||||
TEMP_FAHRENHEIT = f"{DEGREE}F"
|
||||
|
|
|
@ -2,7 +2,11 @@
|
|||
import pytest
|
||||
|
||||
from homeassistant.components.pvpc_hourly_pricing import ATTR_TARIFF, DOMAIN
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, ENERGY_KILO_WATT_HOUR
|
||||
from homeassistant.const import (
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
CURRENCY_EURO,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
)
|
||||
|
||||
from tests.common import load_fixture
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
@ -15,7 +19,10 @@ FIXTURE_JSON_DATA_2019_10_29 = "PVPC_CURV_DD_2019_10_29.json"
|
|||
def check_valid_state(state, tariff: str, value=None, key_attr=None):
|
||||
"""Ensure that sensor has a valid state and attributes."""
|
||||
assert state
|
||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == f"€/{ENERGY_KILO_WATT_HOUR}"
|
||||
assert (
|
||||
state.attributes[ATTR_UNIT_OF_MEASUREMENT]
|
||||
== f"{CURRENCY_EURO}/{ENERGY_KILO_WATT_HOUR}"
|
||||
)
|
||||
try:
|
||||
_ = float(state.state)
|
||||
# safety margins for current electricity price (it shouldn't be out of [0, 0.2])
|
||||
|
|
Loading…
Add table
Reference in a new issue