Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse temperature unit for TemperatureSensor #116

Merged
merged 12 commits into from
Jul 6, 2020
1 change: 1 addition & 0 deletions custom_components/tahoma/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,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"
Expand Down
13 changes: 12 additions & 1 deletion custom_components/tahoma/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
ENERGY_KILO_WATT_HOUR,
POWER_WATT,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
TEMP_KELVIN,
UNIT_PERCENTAGE,
)
from homeassistant.helpers.entity import Entity
Expand All @@ -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,
Expand Down Expand Up @@ -75,7 +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
unit = self.tahoma_device.attributes.get(CORE_MEASURED_VALUE_TYPE)
if unit:
vlebourl marked this conversation as resolved.
Show resolved Hide resolved
return (
TEMP_KELVIN
if "Kelvin" in unit
else TEMP_FAHRENHEIT
if "Fahrenheit" in unit
else TEMP_CELSIUS
)
return TEMP_CELSIUS

if CORE_RELATIVE_HUMIDITY_STATE in states:
Expand Down
18 changes: 14 additions & 4 deletions custom_components/tahoma/tahoma_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,11 @@ def __init__(self, protocol, dataInput):
self.__definitions["states"].append(state["qualifiedName"])
self.__command_def = definition.get("commands")
self.__states_def = definition.get("states")
self.__attributes = {}
vlebourl marked this conversation as resolved.
Show resolved Hide resolved
attributes = dataInput.get("attributes")
if attributes:
for attr in attributes:
self.__attributes[attr["name"]] = attr["value"]
vlebourl marked this conversation as resolved.
Show resolved Hide resolved
# Parse active states
if len(self.state_definitions) > 0:
if "states" in dataInput.keys():
Expand All @@ -629,19 +634,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):
vlebourl marked this conversation as resolved.
Show resolved Hide resolved
"""Return entity attributes if any."""
return self.__attributes
iMicknl marked this conversation as resolved.
Show resolved Hide resolved

def set_active_state(self, name, value):
"""Set active state."""
if name not in self.__active_states.keys():
Expand Down