Fix MELCloud temperature unit (#35003)

The MELCLoud API produces and consumes only Celsius.
This commit is contained in:
Vilppu Vuorinen 2020-05-01 14:33:46 +03:00 committed by GitHub
parent 8ec5e53cf4
commit 66d3832be9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 31 deletions

View File

@ -31,7 +31,6 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TEMP_CELSIUS from homeassistant.const import TEMP_CELSIUS
from homeassistant.helpers import config_validation as cv, entity_platform from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.typing import HomeAssistantType from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.util.temperature import convert as convert_temperature
from . import MelCloudDevice from . import MelCloudDevice
from .const import ( from .const import (
@ -44,7 +43,6 @@ from .const import (
DOMAIN, DOMAIN,
SERVICE_SET_VANE_HORIZONTAL, SERVICE_SET_VANE_HORIZONTAL,
SERVICE_SET_VANE_VERTICAL, SERVICE_SET_VANE_VERTICAL,
TEMP_UNIT_LOOKUP,
) )
SCAN_INTERVAL = timedelta(seconds=60) SCAN_INTERVAL = timedelta(seconds=60)
@ -169,7 +167,7 @@ class AtaDeviceClimate(MelCloudClimate):
@property @property
def temperature_unit(self) -> str: def temperature_unit(self) -> str:
"""Return the unit of measurement used by the platform.""" """Return the unit of measurement used by the platform."""
return TEMP_UNIT_LOOKUP.get(self._device.temp_unit, TEMP_CELSIUS) return TEMP_CELSIUS
@property @property
def hvac_mode(self) -> str: def hvac_mode(self) -> str:
@ -281,9 +279,7 @@ class AtaDeviceClimate(MelCloudClimate):
if min_value is not None: if min_value is not None:
return min_value return min_value
return convert_temperature( return DEFAULT_MIN_TEMP
DEFAULT_MIN_TEMP, TEMP_CELSIUS, self.temperature_unit
)
@property @property
def max_temp(self) -> float: def max_temp(self) -> float:
@ -292,9 +288,7 @@ class AtaDeviceClimate(MelCloudClimate):
if max_value is not None: if max_value is not None:
return max_value return max_value
return convert_temperature( return DEFAULT_MAX_TEMP
DEFAULT_MAX_TEMP, TEMP_CELSIUS, self.temperature_unit
)
class AtwDeviceZoneClimate(MelCloudClimate): class AtwDeviceZoneClimate(MelCloudClimate):
@ -331,7 +325,7 @@ class AtwDeviceZoneClimate(MelCloudClimate):
@property @property
def temperature_unit(self) -> str: def temperature_unit(self) -> str:
"""Return the unit of measurement used by the platform.""" """Return the unit of measurement used by the platform."""
return TEMP_UNIT_LOOKUP.get(self._device.temp_unit, TEMP_CELSIUS) return TEMP_CELSIUS
@property @property
def hvac_mode(self) -> str: def hvac_mode(self) -> str:
@ -391,7 +385,7 @@ class AtwDeviceZoneClimate(MelCloudClimate):
MELCloud API does not expose radiator zone temperature limits. MELCloud API does not expose radiator zone temperature limits.
""" """
return convert_temperature(10, TEMP_CELSIUS, self.temperature_unit) return 10
@property @property
def max_temp(self) -> float: def max_temp(self) -> float:
@ -399,4 +393,4 @@ class AtwDeviceZoneClimate(MelCloudClimate):
MELCloud API does not expose radiator zone temperature limits. MELCloud API does not expose radiator zone temperature limits.
""" """
return convert_temperature(30, TEMP_CELSIUS, self.temperature_unit) return 30

View File

@ -1,7 +1,4 @@
"""Constants for the MELCloud Climate integration.""" """Constants for the MELCloud Climate integration."""
from pymelcloud.const import UNIT_TEMP_CELSIUS, UNIT_TEMP_FAHRENHEIT
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT
DOMAIN = "melcloud" DOMAIN = "melcloud"
@ -15,9 +12,3 @@ ATTR_VANE_VERTICAL_POSITIONS = "vane_vertical_positions"
SERVICE_SET_VANE_HORIZONTAL = "set_vane_horizontal" SERVICE_SET_VANE_HORIZONTAL = "set_vane_horizontal"
SERVICE_SET_VANE_VERTICAL = "set_vane_vertical" SERVICE_SET_VANE_VERTICAL = "set_vane_vertical"
TEMP_UNIT_LOOKUP = {
UNIT_TEMP_CELSIUS: TEMP_CELSIUS,
UNIT_TEMP_FAHRENHEIT: TEMP_FAHRENHEIT,
}
TEMP_UNIT_REVERSE_LOOKUP = {v: k for k, v in TEMP_UNIT_LOOKUP.items()}

View File

@ -12,11 +12,11 @@ from homeassistant.const import (
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from . import MelCloudDevice from . import MelCloudDevice
from .const import DOMAIN, TEMP_UNIT_LOOKUP from .const import DOMAIN
ATTR_MEASUREMENT_NAME = "measurement_name" ATTR_MEASUREMENT_NAME = "measurement_name"
ATTR_ICON = "icon" ATTR_ICON = "icon"
ATTR_UNIT_FN = "unit_fn" ATTR_UNIT = "unit"
ATTR_DEVICE_CLASS = "device_class" ATTR_DEVICE_CLASS = "device_class"
ATTR_VALUE_FN = "value_fn" ATTR_VALUE_FN = "value_fn"
ATTR_ENABLED_FN = "enabled" ATTR_ENABLED_FN = "enabled"
@ -25,7 +25,7 @@ ATA_SENSORS = {
"room_temperature": { "room_temperature": {
ATTR_MEASUREMENT_NAME: "Room Temperature", ATTR_MEASUREMENT_NAME: "Room Temperature",
ATTR_ICON: "mdi:thermometer", ATTR_ICON: "mdi:thermometer",
ATTR_UNIT_FN: lambda x: TEMP_UNIT_LOOKUP.get(x.device.temp_unit, TEMP_CELSIUS), ATTR_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, ATTR_ENABLED_FN: lambda x: True,
@ -33,7 +33,7 @@ ATA_SENSORS = {
"energy": { "energy": {
ATTR_MEASUREMENT_NAME: "Energy", ATTR_MEASUREMENT_NAME: "Energy",
ATTR_ICON: "mdi:factory", ATTR_ICON: "mdi:factory",
ATTR_UNIT_FN: lambda x: ENERGY_KILO_WATT_HOUR, ATTR_UNIT: ENERGY_KILO_WATT_HOUR,
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, ATTR_ENABLED_FN: lambda x: x.device.has_energy_consumed_meter,
@ -43,7 +43,7 @@ ATW_SENSORS = {
"outside_temperature": { "outside_temperature": {
ATTR_MEASUREMENT_NAME: "Outside Temperature", ATTR_MEASUREMENT_NAME: "Outside Temperature",
ATTR_ICON: "mdi:thermometer", ATTR_ICON: "mdi:thermometer",
ATTR_UNIT_FN: lambda x: TEMP_UNIT_LOOKUP.get(x.device.temp_unit, TEMP_CELSIUS), ATTR_UNIT: TEMP_CELSIUS,
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
ATTR_VALUE_FN: lambda x: x.device.outside_temperature, ATTR_VALUE_FN: lambda x: x.device.outside_temperature,
ATTR_ENABLED_FN: lambda x: True, ATTR_ENABLED_FN: lambda x: True,
@ -51,7 +51,7 @@ ATW_SENSORS = {
"tank_temperature": { "tank_temperature": {
ATTR_MEASUREMENT_NAME: "Tank Temperature", ATTR_MEASUREMENT_NAME: "Tank Temperature",
ATTR_ICON: "mdi:thermometer", ATTR_ICON: "mdi:thermometer",
ATTR_UNIT_FN: lambda x: TEMP_UNIT_LOOKUP.get(x.device.temp_unit, TEMP_CELSIUS), ATTR_UNIT: TEMP_CELSIUS,
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
ATTR_VALUE_FN: lambda x: x.device.tank_temperature, ATTR_VALUE_FN: lambda x: x.device.tank_temperature,
ATTR_ENABLED_FN: lambda x: True, ATTR_ENABLED_FN: lambda x: True,
@ -61,7 +61,7 @@ ATW_ZONE_SENSORS = {
"room_temperature": { "room_temperature": {
ATTR_MEASUREMENT_NAME: "Room Temperature", ATTR_MEASUREMENT_NAME: "Room Temperature",
ATTR_ICON: "mdi:thermometer", ATTR_ICON: "mdi:thermometer",
ATTR_UNIT_FN: lambda x: TEMP_UNIT_LOOKUP.get(x.device.temp_unit, TEMP_CELSIUS), ATTR_UNIT: TEMP_CELSIUS,
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
ATTR_VALUE_FN: lambda zone: zone.room_temperature, ATTR_VALUE_FN: lambda zone: zone.room_temperature,
ATTR_ENABLED_FN: lambda x: True, ATTR_ENABLED_FN: lambda x: True,
@ -147,7 +147,7 @@ class MelDeviceSensor(Entity):
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
"""Return the unit of measurement.""" """Return the unit of measurement."""
return self._def[ATTR_UNIT_FN](self._api) return self._def[ATTR_UNIT]
@property @property
def device_class(self): def device_class(self):

View File

@ -18,7 +18,7 @@ from homeassistant.const import TEMP_CELSIUS
from homeassistant.helpers.typing import HomeAssistantType from homeassistant.helpers.typing import HomeAssistantType
from . import DOMAIN, MelCloudDevice from . import DOMAIN, MelCloudDevice
from .const import ATTR_STATUS, TEMP_UNIT_LOOKUP from .const import ATTR_STATUS
async def async_setup_entry( async def async_setup_entry(
@ -80,7 +80,7 @@ class AtwWaterHeater(WaterHeaterDevice):
@property @property
def temperature_unit(self) -> str: def temperature_unit(self) -> str:
"""Return the unit of measurement used by the platform.""" """Return the unit of measurement used by the platform."""
return TEMP_UNIT_LOOKUP.get(self._device.temp_unit, TEMP_CELSIUS) return TEMP_CELSIUS
@property @property
def current_operation(self) -> Optional[str]: def current_operation(self) -> Optional[str]: