diff --git a/custom_components/tahoma/const.py b/custom_components/tahoma/const.py index 562632a28..4b30c3750 100644 --- a/custom_components/tahoma/const.py +++ b/custom_components/tahoma/const.py @@ -132,6 +132,7 @@ CORE_GAS_DETECTION_STATE = "core:GasDetectionState" CORE_GREEN_COLOR_INTENSITY_STATE = "core:GreenColorIntensityState" CORE_LUMINANCE_STATE = "core:LuminanceState" +CORE_MEASURED_VALUE_TYPE = "core:MeasuredValueType" CORE_MEMORIZED_1_POSITION_STATE = "core:Memorized1PositionState" CORE_NAME_STATE = "core:NameState" CORE_OCCUPANCY_STATE = "core:OccupancyState" diff --git a/custom_components/tahoma/sensor.py b/custom_components/tahoma/sensor.py index 9feec2fd6..322b26079 100644 --- a/custom_components/tahoma/sensor.py +++ b/custom_components/tahoma/sensor.py @@ -9,6 +9,8 @@ ENERGY_KILO_WATT_HOUR, POWER_WATT, TEMP_CELSIUS, + TEMP_FAHRENHEIT, + TEMP_KELVIN, UNIT_PERCENTAGE, ) from homeassistant.helpers.entity import Entity @@ -19,6 +21,7 @@ CORE_ELECTRIC_ENERGY_CONSUMPTION_STATE, CORE_ELECTRIC_POWER_CONSUMPTION_STATE, CORE_LUMINANCE_STATE, + CORE_MEASURED_VALUE_TYPE, CORE_RELATIVE_HUMIDITY_STATE, CORE_SUN_ENERGY_STATE, CORE_TEMPERATURE_STATE, @@ -75,8 +78,15 @@ def unit_of_measurement(self): states = self.tahoma_device.active_states if CORE_TEMPERATURE_STATE in states: - # TODO Retrieve core:MeasuredValueType to understand if it is Celsius or Kelvin - return TEMP_CELSIUS + return { + "core:TemperatureInCelsius": TEMP_CELSIUS, + "core:TemperatureInCelcius": TEMP_CELSIUS, + "core:TemperatureInKelvin": TEMP_KELVIN, + "core:TemperatureInFahrenheit": TEMP_FAHRENHEIT, + }.get( + self.tahoma_device.attributes.get(CORE_MEASURED_VALUE_TYPE), + TEMP_CELSIUS, + ) if CORE_RELATIVE_HUMIDITY_STATE in states: return UNIT_PERCENTAGE diff --git a/custom_components/tahoma/tahoma_api.py b/custom_components/tahoma/tahoma_api.py index 147cd838e..56665416e 100644 --- a/custom_components/tahoma/tahoma_api.py +++ b/custom_components/tahoma/tahoma_api.py @@ -614,6 +614,8 @@ def __init__(self, protocol, dataInput): self.__definitions["states"].append(state["qualifiedName"]) self.__command_def = definition.get("commands") self.__states_def = definition.get("states") + attributes = dataInput.get("attributes", {}) + self.__attributes = {attr["name"]: attr["value"] for attr in attributes} # Parse active states if len(self.state_definitions) > 0: if "states" in dataInput.keys(): @@ -629,19 +631,24 @@ def label(self): @property def command_definitions(self): - """List of command devinitions.""" - return self.__definitions["commands"] + """List of command definitions.""" + return self.__command_def @property def state_definitions(self): - """State of command devinition.""" - return self.__definitions["states"] + """List of state definition.""" + return self.__states_def @property def active_states(self): """Get active states.""" return self.__active_states + @property + def attributes(self): + """Return entity attributes if any.""" + return self.__attributes + def set_active_state(self, name, value): """Set active state.""" if name not in self.__active_states.keys():