Skip to content

Commit

Permalink
Merge pull request #63 from tom3q/sensor-display-fixes
Browse files Browse the repository at this point in the history
Fix display of power, humidity and temperature values
  • Loading branch information
scottyphillips authored Feb 7, 2022
2 parents 0c8b875 + 788be7f commit e507d4a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
13 changes: 7 additions & 6 deletions custom_components/echonetlite/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,18 @@ def current_temperature(self):
return None
return self._connector._update_data[ENL_HVAC_ROOM_TEMP]
else:
return 'unavailable'
return None
else:
return self._connector._update_data[ENL_HVAC_SET_TEMP]

@property
def target_temperature(self):
"""Return the temperature we try to reach."""
if ENL_HVAC_SET_TEMP in self._connector._update_data:
return self._connector._update_data[ENL_HVAC_SET_TEMP]
else:
return 'unavailable'
temp = self._connector._update_data[ENL_HVAC_SET_TEMP]
if temp != -3:
return temp
return None

@property
def target_temperature_step(self):
Expand Down Expand Up @@ -196,7 +197,7 @@ def is_on(self):
@property
def fan_mode(self):
"""Return the fan setting."""
return self._connector._update_data[ENL_FANSPEED] if ENL_FANSPEED in self._connector._update_data else "unavailable"
return self._connector._update_data[ENL_FANSPEED] if ENL_FANSPEED in self._connector._update_data else None

@property
def fan_modes(self):
Expand All @@ -222,7 +223,7 @@ def swing_modes(self):
@property
def swing_mode(self):
"""Return the swing mode setting."""
return self._connector._update_data[ENL_AIR_VERT] if ENL_AIR_VERT in self._connector._update_data else "unavailable"
return self._connector._update_data[ENL_AIR_VERT] if ENL_AIR_VERT in self._connector._update_data else None

async def async_set_swing_mode(self, swing_mode):
"""Set new swing mode."""
Expand Down
6 changes: 3 additions & 3 deletions custom_components/echonetlite/const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Constants for the echonetlite integration."""
from homeassistant.const import CONF_ICON, CONF_TYPE, DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_ENERGY, DEVICE_CLASS_HUMIDITY
from homeassistant.const import CONF_ICON, CONF_TYPE, DEVICE_CLASS_POWER, DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_ENERGY, DEVICE_CLASS_HUMIDITY
from homeassistant.components.sensor import ATTR_STATE_CLASS, STATE_CLASS_MEASUREMENT, STATE_CLASS_TOTAL_INCREASING
from pychonet.HomeAirConditioner import (
ENL_FANSPEED,
Expand Down Expand Up @@ -43,7 +43,7 @@
0x30: {
0x84: {
CONF_ICON: "mdi:flash",
CONF_TYPE: DEVICE_CLASS_ENERGY,
CONF_TYPE: DEVICE_CLASS_POWER,
CONF_STATE_CLASS: STATE_CLASS_MEASUREMENT
},
0x85: {
Expand All @@ -70,7 +70,7 @@
0x35: {
0x84: {
CONF_ICON: "mdi:flash",
CONF_TYPE: DEVICE_CLASS_ENERGY,
CONF_TYPE: DEVICE_CLASS_POWER,
CONF_STATE_CLASS: STATE_CLASS_MEASUREMENT
},
0x85: {
Expand Down
23 changes: 19 additions & 4 deletions custom_components/echonetlite/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import logging

from homeassistant.const import (
CONF_ICON, CONF_TYPE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_ENERGY,
CONF_ICON, CONF_TYPE, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_POWER,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_ENERGY, PERCENTAGE, POWER_WATT,
TEMP_CELSIUS, ENERGY_WATT_HOUR,
STATE_UNAVAILABLE
)
Expand Down Expand Up @@ -105,6 +105,10 @@ def __init__(self, instance, op_code, attributes, name=None) -> None:
self._unit_of_measurement = TEMP_CELSIUS
elif self._sensor_attributes[CONF_TYPE] == DEVICE_CLASS_ENERGY:
self._unit_of_measurement = ENERGY_WATT_HOUR
elif self._sensor_attributes[CONF_TYPE] == DEVICE_CLASS_POWER:
self._unit_of_measurement = POWER_WATT
elif self._sensor_attributes[CONF_TYPE] == DEVICE_CLASS_HUMIDITY:
self._unit_of_measurement = PERCENTAGE
else:
self._unit_of_measurement = None

Expand Down Expand Up @@ -140,14 +144,25 @@ def native_value(self) -> StateType:
"""Return the state of the sensor."""
if self._instance._update_data[self._op_code] is None:
return STATE_UNAVAILABLE
elif self._sensor_attributes[CONF_TYPE] == DEVICE_CLASS_TEMPERATURE:
elif self._sensor_attributes[CONF_TYPE] in [
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_HUMIDITY
]:
if self._op_code in self._instance._update_data:
if self._instance._update_data[self._op_code] == 126:
if self._instance._update_data[self._op_code] in [126, 253]:
return STATE_UNAVAILABLE
else:
return self._instance._update_data[self._op_code]
else:
return STATE_UNAVAILABLE
elif self._sensor_attributes[CONF_TYPE] == DEVICE_CLASS_POWER:
if self._op_code in self._instance._update_data:
# Underflow (less than 1 W)
if self._instance._update_data[self._op_code] == 65534:
return 1
else:
return self._instance._update_data[self._op_code]
else:
return STATE_UNAVAILABLE
elif self._op_code in self._instance._update_data:
if isinstance(self._instance._update_data[self._op_code], (int, float)):
return self._instance._update_data[self._op_code]
Expand Down

0 comments on commit e507d4a

Please sign in to comment.