mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Tweaks for the iotawatt integration (#55510)
This commit is contained in:
parent
bcf97cb308
commit
9284f7b147
@ -8,7 +8,6 @@ from iotawattpy.sensor import Sensor
|
|||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
STATE_CLASS_MEASUREMENT,
|
STATE_CLASS_MEASUREMENT,
|
||||||
STATE_CLASS_TOTAL_INCREASING,
|
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
)
|
)
|
||||||
@ -47,12 +46,14 @@ ENTITY_DESCRIPTION_KEY_MAP: dict[str, IotaWattSensorEntityDescription] = {
|
|||||||
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
device_class=DEVICE_CLASS_CURRENT,
|
device_class=DEVICE_CLASS_CURRENT,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
),
|
),
|
||||||
"Hz": IotaWattSensorEntityDescription(
|
"Hz": IotaWattSensorEntityDescription(
|
||||||
"Hz",
|
"Hz",
|
||||||
native_unit_of_measurement=FREQUENCY_HERTZ,
|
native_unit_of_measurement=FREQUENCY_HERTZ,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
icon="mdi:flash",
|
icon="mdi:flash",
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
),
|
),
|
||||||
"PF": IotaWattSensorEntityDescription(
|
"PF": IotaWattSensorEntityDescription(
|
||||||
"PF",
|
"PF",
|
||||||
@ -60,6 +61,7 @@ ENTITY_DESCRIPTION_KEY_MAP: dict[str, IotaWattSensorEntityDescription] = {
|
|||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
device_class=DEVICE_CLASS_POWER_FACTOR,
|
device_class=DEVICE_CLASS_POWER_FACTOR,
|
||||||
value=lambda value: value * 100,
|
value=lambda value: value * 100,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
),
|
),
|
||||||
"Watts": IotaWattSensorEntityDescription(
|
"Watts": IotaWattSensorEntityDescription(
|
||||||
"Watts",
|
"Watts",
|
||||||
@ -70,7 +72,6 @@ ENTITY_DESCRIPTION_KEY_MAP: dict[str, IotaWattSensorEntityDescription] = {
|
|||||||
"WattHours": IotaWattSensorEntityDescription(
|
"WattHours": IotaWattSensorEntityDescription(
|
||||||
"WattHours",
|
"WattHours",
|
||||||
native_unit_of_measurement=ENERGY_WATT_HOUR,
|
native_unit_of_measurement=ENERGY_WATT_HOUR,
|
||||||
state_class=STATE_CLASS_TOTAL_INCREASING,
|
|
||||||
device_class=DEVICE_CLASS_ENERGY,
|
device_class=DEVICE_CLASS_ENERGY,
|
||||||
),
|
),
|
||||||
"VA": IotaWattSensorEntityDescription(
|
"VA": IotaWattSensorEntityDescription(
|
||||||
@ -78,24 +79,28 @@ ENTITY_DESCRIPTION_KEY_MAP: dict[str, IotaWattSensorEntityDescription] = {
|
|||||||
native_unit_of_measurement=POWER_VOLT_AMPERE,
|
native_unit_of_measurement=POWER_VOLT_AMPERE,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
icon="mdi:flash",
|
icon="mdi:flash",
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
),
|
),
|
||||||
"VAR": IotaWattSensorEntityDescription(
|
"VAR": IotaWattSensorEntityDescription(
|
||||||
"VAR",
|
"VAR",
|
||||||
native_unit_of_measurement=VOLT_AMPERE_REACTIVE,
|
native_unit_of_measurement=VOLT_AMPERE_REACTIVE,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
icon="mdi:flash",
|
icon="mdi:flash",
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
),
|
),
|
||||||
"VARh": IotaWattSensorEntityDescription(
|
"VARh": IotaWattSensorEntityDescription(
|
||||||
"VARh",
|
"VARh",
|
||||||
native_unit_of_measurement=VOLT_AMPERE_REACTIVE_HOURS,
|
native_unit_of_measurement=VOLT_AMPERE_REACTIVE_HOURS,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
icon="mdi:flash",
|
icon="mdi:flash",
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
),
|
),
|
||||||
"Volts": IotaWattSensorEntityDescription(
|
"Volts": IotaWattSensorEntityDescription(
|
||||||
"Volts",
|
"Volts",
|
||||||
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
device_class=DEVICE_CLASS_VOLTAGE,
|
device_class=DEVICE_CLASS_VOLTAGE,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
"""Test setting up sensors."""
|
"""Test setting up sensors."""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import ATTR_STATE_CLASS, DEVICE_CLASS_ENERGY
|
||||||
ATTR_STATE_CLASS,
|
|
||||||
DEVICE_CLASS_ENERGY,
|
|
||||||
STATE_CLASS_TOTAL_INCREASING,
|
|
||||||
)
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_DEVICE_CLASS,
|
ATTR_DEVICE_CLASS,
|
||||||
ATTR_FRIENDLY_NAME,
|
ATTR_FRIENDLY_NAME,
|
||||||
@ -37,7 +33,7 @@ async def test_sensor_type_input(hass, mock_iotawatt):
|
|||||||
state = hass.states.get("sensor.my_sensor")
|
state = hass.states.get("sensor.my_sensor")
|
||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.state == "23"
|
assert state.state == "23"
|
||||||
assert state.attributes[ATTR_STATE_CLASS] == STATE_CLASS_TOTAL_INCREASING
|
assert ATTR_STATE_CLASS not in state.attributes
|
||||||
assert state.attributes[ATTR_FRIENDLY_NAME] == "My Sensor"
|
assert state.attributes[ATTR_FRIENDLY_NAME] == "My Sensor"
|
||||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == ENERGY_WATT_HOUR
|
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == ENERGY_WATT_HOUR
|
||||||
assert state.attributes[ATTR_DEVICE_CLASS] == DEVICE_CLASS_ENERGY
|
assert state.attributes[ATTR_DEVICE_CLASS] == DEVICE_CLASS_ENERGY
|
||||||
|
Loading…
x
Reference in New Issue
Block a user