Skip to content

Commit

Permalink
Parse temperature unit for TemperatureSensor (#116)
Browse files Browse the repository at this point in the history
Co-authored-by: tetienne <[email protected]>
  • Loading branch information
vlebourl and tetienne authored Jul 6, 2020
1 parent eefe27c commit b56c750
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions custom_components/tahoma/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 12 additions & 2 deletions 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,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
Expand Down
15 changes: 11 additions & 4 deletions custom_components/tahoma/tahoma_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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():
Expand Down

0 comments on commit b56c750

Please sign in to comment.