mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Remove energy sensor from incompatible Ata devices (#31831)
An AtaDevice has a boolean flag describing whether it supports energy consumption metering. The flag was ignored resulting in sensor entities reporting constant 0 kWh consumption. * Update pymelcloud dependency to support the has_energy_consumed_meter flag. * Add ATTR_ENABLED_FN to sensor definitions for filtering out unsupported sensors. * Fix typing issue in sensor constructor. * Remove unused UnitSystem constructor parameter.
This commit is contained in:
parent
043d36f7c6
commit
614be5c1bb
@ -3,7 +3,7 @@
|
|||||||
"name": "MELCloud",
|
"name": "MELCloud",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/melcloud",
|
"documentation": "https://www.home-assistant.io/integrations/melcloud",
|
||||||
"requirements": ["pymelcloud==2.0.0"],
|
"requirements": ["pymelcloud==2.1.0"],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": ["@vilppuvuorinen"]
|
"codeowners": ["@vilppuvuorinen"]
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
"""Support for MelCloud device sensors."""
|
"""Support for MelCloud device sensors."""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pymelcloud import DEVICE_TYPE_ATA, AtaDevice
|
from pymelcloud import DEVICE_TYPE_ATA
|
||||||
|
|
||||||
from homeassistant.const import DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS
|
from homeassistant.const import DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.util.unit_system import UnitSystem
|
|
||||||
|
|
||||||
|
from . import MelCloudDevice
|
||||||
from .const import DOMAIN, TEMP_UNIT_LOOKUP
|
from .const import DOMAIN, TEMP_UNIT_LOOKUP
|
||||||
|
|
||||||
ATTR_MEASUREMENT_NAME = "measurement_name"
|
ATTR_MEASUREMENT_NAME = "measurement_name"
|
||||||
@ -14,6 +14,7 @@ ATTR_ICON = "icon"
|
|||||||
ATTR_UNIT_FN = "unit_fn"
|
ATTR_UNIT_FN = "unit_fn"
|
||||||
ATTR_DEVICE_CLASS = "device_class"
|
ATTR_DEVICE_CLASS = "device_class"
|
||||||
ATTR_VALUE_FN = "value_fn"
|
ATTR_VALUE_FN = "value_fn"
|
||||||
|
ATTR_ENABLED_FN = "enabled"
|
||||||
|
|
||||||
SENSORS = {
|
SENSORS = {
|
||||||
"room_temperature": {
|
"room_temperature": {
|
||||||
@ -22,6 +23,7 @@ SENSORS = {
|
|||||||
ATTR_UNIT_FN: lambda x: TEMP_UNIT_LOOKUP.get(x.device.temp_unit, TEMP_CELSIUS),
|
ATTR_UNIT_FN: lambda x: TEMP_UNIT_LOOKUP.get(x.device.temp_unit, TEMP_CELSIUS),
|
||||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
|
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
|
||||||
ATTR_VALUE_FN: lambda x: x.device.room_temperature,
|
ATTR_VALUE_FN: lambda x: x.device.room_temperature,
|
||||||
|
ATTR_ENABLED_FN: lambda x: True,
|
||||||
},
|
},
|
||||||
"energy": {
|
"energy": {
|
||||||
ATTR_MEASUREMENT_NAME: "Energy",
|
ATTR_MEASUREMENT_NAME: "Energy",
|
||||||
@ -29,6 +31,7 @@ SENSORS = {
|
|||||||
ATTR_UNIT_FN: lambda x: "kWh",
|
ATTR_UNIT_FN: lambda x: "kWh",
|
||||||
ATTR_DEVICE_CLASS: None,
|
ATTR_DEVICE_CLASS: None,
|
||||||
ATTR_VALUE_FN: lambda x: x.device.total_energy_consumed,
|
ATTR_VALUE_FN: lambda x: x.device.total_energy_consumed,
|
||||||
|
ATTR_ENABLED_FN: lambda x: x.device.has_energy_consumed_meter,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,9 +43,10 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||||||
mel_devices = hass.data[DOMAIN].get(entry.entry_id)
|
mel_devices = hass.data[DOMAIN].get(entry.entry_id)
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
MelCloudSensor(mel_device, measurement, definition, hass.config.units)
|
MelCloudSensor(mel_device, measurement, definition)
|
||||||
for measurement, definition in SENSORS.items()
|
for measurement, definition in SENSORS.items()
|
||||||
for mel_device in mel_devices[DEVICE_TYPE_ATA]
|
for mel_device in mel_devices[DEVICE_TYPE_ATA]
|
||||||
|
if definition[ATTR_ENABLED_FN](mel_device)
|
||||||
],
|
],
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
@ -51,7 +55,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||||||
class MelCloudSensor(Entity):
|
class MelCloudSensor(Entity):
|
||||||
"""Representation of a Sensor."""
|
"""Representation of a Sensor."""
|
||||||
|
|
||||||
def __init__(self, device: AtaDevice, measurement, definition, units: UnitSystem):
|
def __init__(self, device: MelCloudDevice, measurement, definition):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self._api = device
|
self._api = device
|
||||||
self._name_slug = device.name
|
self._name_slug = device.name
|
||||||
|
@ -1361,7 +1361,7 @@ pymailgunner==1.4
|
|||||||
pymediaroom==0.6.4
|
pymediaroom==0.6.4
|
||||||
|
|
||||||
# homeassistant.components.melcloud
|
# homeassistant.components.melcloud
|
||||||
pymelcloud==2.0.0
|
pymelcloud==2.1.0
|
||||||
|
|
||||||
# homeassistant.components.somfy
|
# homeassistant.components.somfy
|
||||||
pymfy==0.7.1
|
pymfy==0.7.1
|
||||||
|
@ -494,7 +494,7 @@ pylitejet==0.1
|
|||||||
pymailgunner==1.4
|
pymailgunner==1.4
|
||||||
|
|
||||||
# homeassistant.components.melcloud
|
# homeassistant.components.melcloud
|
||||||
pymelcloud==2.0.0
|
pymelcloud==2.1.0
|
||||||
|
|
||||||
# homeassistant.components.somfy
|
# homeassistant.components.somfy
|
||||||
pymfy==0.7.1
|
pymfy==0.7.1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user