Home Information - Your home, your data, organized.
Python
Added more logic and styling for status display rendering.
Anthony Cassandra8b3d1ddf52a7
diff --git a/src/hi/apps/entity/templates/entity/panes/entity_state_info_list.html b/src/hi/apps/entity/templates/entity/panes/entity_state_info_list.htmlindex ecb34d71..9efffbe9 100644--- a/src/hi/apps/entity/templates/entity/panes/entity_state_info_list.html+++ b/src/hi/apps/entity/templates/entity/panes/entity_state_info_list.html@@ -3,7 +3,7 @@<ul>{% for entity_state in entity_state_list %}<li>- {{ entity_state.name }}+ {{ entity_state.name }} [{{ entity_state.entity_state_type }}]<ul><li>Sensorsdiff --git a/src/hi/apps/monitor/status_display_data.py b/src/hi/apps/monitor/status_display_data.pyindex 3c6d5cc5..4a201ecf 100644--- a/src/hi/apps/monitor/status_display_data.py+++ b/src/hi/apps/monitor/status_display_data.py@@ -36,7 +36,6 @@ class StatusStyle:fill_color = 'red',fill_opacity = 0.5,)-MovementRecent = SvgStatusStyle(status_value = 'recent',stroke_color = 'orange',@@ -44,7 +43,6 @@ class StatusStyle:fill_color = 'orange',fill_opacity = 0.5,)-MovementPast = SvgStatusStyle(status_value = 'past',stroke_color = 'yellow',@@ -52,7 +50,6 @@ class StatusStyle:fill_color = 'yellow',fill_opacity = 0.5,)-MovementIdle = SvgStatusStyle(status_value = 'idle',stroke_color = '#888888',@@ -60,6 +57,62 @@ class StatusStyle:fill_color = 'white',fill_opacity = 0.0,)+ On = SvgStatusStyle(+ status_value = 'on',+ stroke_color = 'green',+ stroke_width = None,+ fill_color = 'green',+ fill_opacity = 0.5,+ )+ Off = SvgStatusStyle(+ status_value = 'off',+ stroke_color = '#888888',+ stroke_width = None,+ fill_color = '#888888',+ fill_opacity = 0.5,+ )+ Open = SvgStatusStyle(+ status_value = 'open',+ stroke_color = 'green',+ stroke_width = None,+ fill_color = 'green',+ fill_opacity = 0.5,+ )+ Closed = SvgStatusStyle(+ status_value = 'closed',+ stroke_color = '#888888',+ stroke_width = None,+ fill_color = '#888888',+ fill_opacity = 0.5,+ )+ Connected = SvgStatusStyle(+ status_value = 'connected',+ stroke_color = 'green',+ stroke_width = None,+ fill_color = 'green',+ fill_opacity = 0.5,+ )+ Disconnected = SvgStatusStyle(+ status_value = 'disconnected',+ stroke_color = 'red',+ stroke_width = None,+ fill_color = 'red',+ fill_opacity = 0.5,+ )+ High = SvgStatusStyle(+ status_value = 'high',+ stroke_color = 'green',+ stroke_width = None,+ fill_color = 'green',+ fill_opacity = 0.5,+ )+ Low = SvgStatusStyle(+ status_value = 'low',+ stroke_color = 'red',+ stroke_width = None,+ fill_color = 'red',+ fill_opacity = 0.5,+ )@dataclass@@ -68,7 +121,7 @@ class StatusDisplayData:sensor_response_list : List[ SensorResponse ]def __post_init__(self):- self._svg_status_style = self.get_svg_status_style()+ self._svg_status_style = self._get_svg_status_style()return@property@@ -103,14 +156,49 @@ class StatusDisplayData:return self.sensor_response_list[1].timestampreturn None- def get_svg_status_style(self):+ def _get_svg_status_style(self):if self.entity_state.entity_state_type == EntityStateType.MOVEMENT:- return self.get_movement_status_style()+ return self._get_movement_status_style()++ if self.entity_state.entity_state_type == EntityStateType.PRESENCE:+ return self._get_presence_status_style()- return None+ if self.entity_state.entity_state_type == EntityStateType.ON_OFF:+ return self._get_on_off_status_style()- def get_movement_status_style( self ):+ if self.entity_state.entity_state_type == EntityStateType.OPEN_CLOSE:+ return self._get_open_close_status_style()++ if self.entity_state.entity_state_type == EntityStateType.CONNECTIVITY:+ return self._get_connectivity_status_style()++ if self.entity_state.entity_state_type == EntityStateType.HIGH_LOW:+ return self._get_high_low_status_style()+++ # TODO: These should map the latest value into a continuous range of colors/opacity+ #+ # EntityStateType.AIR_PRESSURE+ # EntityStateType.BANDWIDTH_USAGE+ # EntityStateType.ELECTRIC_USAGE+ # EntityStateType.HUMIDITY+ # EntityStateType.LIGHT_LEVEL+ # EntityStateType.MOISTURE+ # EntityStateType.SOUND_LEVEL+ # EntityStateType.TEMPERATURE+ # EntityStateType.WATER_FLOW+ # EntityStateType.WIND_SPEED++ return SvgStatusStyle(+ status_value = self.latest_sensor_value,+ stroke_color = None,+ stroke_width = None,+ fill_color = None,+ fill_opacity = None,+ )++ def _get_movement_status_style( self ):if self.latest_sensor_value == str(SensorValue.MOVEMENT_ACTIVE):return StatusStyle.MovementActive@@ -125,3 +213,50 @@ class StatusDisplayData:return StatusStyle.MovementIdle+ def _get_presence_status_style( self ):++ if self.latest_sensor_value == str(SensorValue.PRESENCE_ACTIVE):+ return StatusStyle.PresenceActive++ if self.penultimate_sensor_value == str(SensorValue.PRESENCE_ACTIVE):+ presence_timedelta = datetimeproxy.now() - self.penultimate_sensor_timestamp+ if presence_timedelta.seconds < 30:+ return StatusStyle.MovementRecent++ elif presence_timedelta.seconds < 60:+ return StatusStyle.MovementPast++ return StatusStyle.MovementIdle++ def _get_on_off_status_style( self ):++ if self.latest_sensor_value == str(SensorValue.ON):+ return StatusStyle.On+ if self.latest_sensor_value == str(SensorValue.OFF):+ return StatusStyle.Off+ return None++ def _get_open_close_status_style( self ):++ if self.latest_sensor_value == str(SensorValue.OPEN):+ return StatusStyle.Open+ if self.latest_sensor_value == str(SensorValue.CLOSED):+ return StatusStyle.Closed+ return None++ def _get_connectivity_status_style( self ):++ if self.latest_sensor_value == str(SensorValue.CONNECTED):+ return StatusStyle.Connected+ if self.latest_sensor_value == str(SensorValue.DISCONNECTED):+ return StatusStyle.Disconnected+ return None++ def _get_high_low_status_style( self ):++ if self.latest_sensor_value == str(SensorValue.HIGH):+ return StatusStyle.High+ if self.latest_sensor_value == str(SensorValue.LOW):+ return StatusStyle.Low+ return None+diff --git a/src/hi/apps/sense/enums.py b/src/hi/apps/sense/enums.pyindex cf582300..9b8545c2 100644--- a/src/hi/apps/sense/enums.py+++ b/src/hi/apps/sense/enums.py@@ -11,8 +11,17 @@ class SensorValue(LabeledEnum):MOVEMENT_ACTIVE = ( 'Active', '' )MOVEMENT_IDLE = ( 'Idle', '' )- BINARY_ON = ( 'On', '' )- BINARY_OFF = ( 'Off', '' )+ ON = ( 'On', '' )+ OFF = ( 'Off', '' )OPEN = ( 'Open', '' )- CLOSE = ( 'Close', '' )+ CLOSED = ( 'Closed', '' )++ CONNECTED = ( 'Connected', '' )+ DISCONNECTED = ( 'Disconnected', '' )++ HIGH = ( 'High', '' )+ LOW = ( 'Low', '' )++ PRESENCE_ACTIVE = ( 'Active', '' )+ PRESENCE_IDLE = ( 'Idle', '' )diff --git a/src/hi/integrations/hass/hass_converter.py b/src/hi/integrations/hass/hass_converter.pyindex b0143521..3019d224 100644--- a/src/hi/integrations/hass/hass_converter.py+++ b/src/hi/integrations/hass/hass_converter.py@@ -520,13 +520,13 @@ class HassConverter:if hass_state.device_class in HassApi.OPEN_CLOSE_DEVICE_CLASS_SET:return str(SensorValue.OPEN)else:- return str(SensorValue.BINARY_ON)+ return str(SensorValue.ON)elif hass_state.state_value.lower() == 'off':if hass_state.device_class in HassApi.OPEN_CLOSE_DEVICE_CLASS_SET:- return str(SensorValue.CLOSE)+ return str(SensorValue.CLOSED)else:- return str(SensorValue.BINARY_OFF)+ return str(SensorValue.OFF)else:logger.warning( f'Unknown HAss binary state value "{hass_state.state_value}".' )return Nonediff --git a/src/hi/static/css/main.css b/src/hi/static/css/main.cssindex e05b1c07..a3eb7fa6 100644--- a/src/hi/static/css/main.css+++ b/src/hi/static/css/main.css@@ -198,14 +198,35 @@ g[status="active"] {outline: 2px solid red;filter: drop-shadow(0 0 5px red);}-g[status="recent"] {outline: 2px solid orange;filter: drop-shadow(0 0 5px orange);}--g[status="past"] {outline: 2px solid yellow;filter: drop-shadow(0 0 5px yellow);}+g[status="on"] {+ outline: 5px solid green;+ filter: drop-shadow(0 0 5px green);+}+g[status="open"] {+ outline: 5px solid red;+ filter: drop-shadow(0 0 5px red);+}+g[status="connected"] {+ outline: 5px solid green;+ filter: drop-shadow(0 0 5px green);+}+g[status="disconnected"] {+ outline: 5px solid red;+ filter: drop-shadow(0 0 5px red);+}+g[status="high"] {+ outline: 5px solid green;+ filter: drop-shadow(0 0 5px green);+}+g[status="low"] {+ outline: 5px solid red;+ filter: drop-shadow(0 0 5px red);+}