Home Information - Your home, your data, organized.
Python
Better groupings fo entity types for edit selections.
Anthony Cassandra548e2bad4f3e
diff --git a/src/hi/apps/collection/collection_manager.py b/src/hi/apps/collection/collection_manager.pyindex cda29178..22fe8b04 100644--- a/src/hi/apps/collection/collection_manager.py+++ b/src/hi/apps/collection/collection_manager.py@@ -6,6 +6,7 @@ from django.http import HttpRequestfrom hi.apps.collection.edit.forms import CollectionPositionFormfrom hi.apps.common.singleton import Singleton+from hi.apps.entity.enums import EntityGroupTypefrom hi.apps.entity.models import Entityfrom hi.apps.location.models import Location, LocationViewfrom hi.apps.location.svg_item_factory import SvgItemFactory@@ -282,18 +283,20 @@ class CollectionManager(Singleton):entity = entity,exists_in_collection = exists_in_collection,)-- if entity.entity_type not in entity_collection_group_dict:++ entity_group_type = EntityGroupType.from_entity_type( entity.entity_type )++ if entity_group_type not in entity_collection_group_dict:entity_collection_group = EntityCollectionGroup(collection = collection,- entity_type = entity.entity_type,+ entity_group_type = entity_group_type,)- entity_collection_group_dict[entity.entity_type] = entity_collection_group- entity_collection_group_dict[entity.entity_type].item_list.append( entity_collection_item )+ entity_collection_group_dict[entity_group_type] = entity_collection_group+ entity_collection_group_dict[entity_group_type].item_list.append( entity_collection_item )continueentity_collection_group_list = list( entity_collection_group_dict.values() )- entity_collection_group_list.sort( key = lambda item : item.entity_type.label )+ entity_collection_group_list.sort( key = lambda item : item.entity_group_type.label )return entity_collection_group_listdef toggle_entity_in_collection( self, entity : Entity, collection : Collection ) -> bool:diff --git a/src/hi/apps/collection/templates/collection/edit/panes/collection_manage_items.html b/src/hi/apps/collection/templates/collection/edit/panes/collection_manage_items.htmlindex 83ad6f7a..46d4609f 100644--- a/src/hi/apps/collection/templates/collection/edit/panes/collection_manage_items.html+++ b/src/hi/apps/collection/templates/collection/edit/panes/collection_manage_items.html@@ -17,7 +17,7 @@{% for entity_collection_group in entity_collection_group_list %}<div class="">- <div class="h5">{{ entity_collection_group.entity_type.label }}</div>+ <div class="h5">{{ entity_collection_group.entity_group_type.label }}</div>{% for entity_collection_item in entity_collection_group.item_list %}{% include "collection/edit/panes/collection_entity_toggle.html" with collection=entity_collection_group.collection entity=entity_collection_item.entity exists_in_collection=entity_collection_item.exists_in_collection %}{% endfor %}diff --git a/src/hi/apps/collection/transient_models.py b/src/hi/apps/collection/transient_models.pyindex ff94820f..25ef6d48 100644--- a/src/hi/apps/collection/transient_models.py+++ b/src/hi/apps/collection/transient_models.py@@ -2,7 +2,7 @@ from dataclasses import dataclass, fieldfrom typing import Listfrom hi.apps.collection.edit.forms import CollectionForm, CollectionPositionForm-from hi.apps.entity.enums import EntityType+from hi.apps.entity.enums import EntityGroupType, EntityTypefrom hi.apps.entity.models import Entityfrom hi.apps.monitor.transient_models import EntityStatusData@@ -45,9 +45,9 @@ class EntityCollectionItem:@dataclassclass EntityCollectionGroup:- collection : Collection- entity_type : EntityType- item_list : List[EntityCollectionItem] = field( default_factory = list )+ collection : Collection+ entity_group_type : EntityGroupType+ item_list : List[EntityCollectionItem] = field( default_factory = list )@dataclassdiff --git a/src/hi/apps/entity/entity_manager.py b/src/hi/apps/entity/entity_manager.pyindex cb463367..451d4b84 100644--- a/src/hi/apps/entity/entity_manager.py+++ b/src/hi/apps/entity/entity_manager.py@@ -14,6 +14,7 @@ from hi.apps.location.svg_item_factory import SvgItemFactoryfrom .delegation_manager import DelegationManagerfrom .enums import (+ EntityGroupType,EntityPairingType,EntityStateType,)@@ -316,21 +317,21 @@ class EntityManager(Singleton):entity = entity,exists_in_view = bool( entity in existing_entity_set ),)-- if entity.entity_type not in entity_view_group_dict:+ entity_group_type = EntityGroupType.from_entity_type( entity.entity_type )+ if entity_group_type not in entity_view_group_dict:entity_view_group = EntityViewGroup(- entity_type = entity.entity_type,+ entity_group_type = entity_group_type,)- entity_view_group_dict[entity.entity_type] = entity_view_group- entity_view_group_dict[entity.entity_type].item_list.append( entity_view_item )+ entity_view_group_dict[entity_group_type] = entity_view_group+ entity_view_group_dict[entity_group_type].item_list.append( entity_view_item )continue- for entity_type, entity_view_group in entity_view_group_dict.items():+ for entity_group_type, entity_view_group in entity_view_group_dict.items():entity_view_group.item_list.sort( key = lambda item : item.entity.name )continueentity_view_group_list = list( entity_view_group_dict.values() )- entity_view_group_list.sort( key = lambda item : item.entity_type.label )+ entity_view_group_list.sort( key = lambda item : item.entity_group_type.label )return entity_view_group_listdef adjust_principal_entities( self, entity : Entity, desired_principal_entity_ids : Set[ int ] ):diff --git a/src/hi/apps/entity/enums.py b/src/hi/apps/entity/enums.pyindex 68d9806a..110e2b6a 100644--- a/src/hi/apps/entity/enums.py+++ b/src/hi/apps/entity/enums.py@@ -1,3 +1,5 @@+from typing import Set+from hi.apps.common.enums import LabeledEnum@@ -12,6 +14,7 @@ class EntityType(LabeledEnum):ACCESS_POINT = ( 'Access Point', '' )APPLIANCE = ( 'Appliance', '' )AREA = ( 'Area', '' )+ ATTIC_STAIRS = ( 'Attic Stairs', '' )AUTOMOBILE = ( 'Automobile', '' )AV_RECEIVER = ( 'A/V Receiver', '' ) # Controls Speakers/TVBAROMETER = ( 'Barometer', '' )@@ -49,6 +52,7 @@ class EntityType(LabeledEnum):MOTION_SENSOR = ( 'Motion Sensor', '' )MOTOR = ( 'Motor', '' )NETWORK_SWITCH = ( 'Network Switch', '' )+ ON_OFF_SWITCH = ( 'On/Off Switch', '' )OPEN_CLOSE_SENSOR = ( 'Open/Close Sensor', '' )OTHER = ( 'Other', '' ) # Will use generic visual elementOVEN = ( 'Oven', '' )@@ -63,8 +67,11 @@ class EntityType(LabeledEnum):SERVICE = ( 'Service' , '' )SEWER_LINE = ( 'Sewer Line', '' )SHOWER = ( 'Shower', '' )+ SHED = ( 'Shed', '' )SINK = ( 'Sink', '' )+ SKYLIGHT = ( 'Skylight', '' )SPEAKER = ( 'Speaker', '' )+ SPEAKER_WIRE = ( 'Speaker Wire', '' )SPRINKLER_HEAD = ( 'Sprinkler Head', '' )SPRINKLER_VALVE = ( 'Sprinkler Valve', '' ) # Controls sprinkler headsSPRINKLER_WIRE = ( 'Sprinkler Wire', '' )@@ -199,3 +206,140 @@ class EntityPairingType(LabeledEnum):PRINCIPAL = ( 'Principal', '' )DELEGATE = ( 'Delegate', '' )++class EntityGroupType(LabeledEnum):++ APPLIANCES = ( 'Appliances', '', {+ EntityType.APPLIANCE,+ EntityType.CLOTHES_DRYER,+ EntityType.CLOTHES_WASHER,+ EntityType.COOKTOP,+ EntityType.MICROWAVE_OVEN,+ EntityType.OVEN,+ EntityType.REFRIGERATOR,+ EntityType.WATER_HEATER,+ })+ AREAS = ( 'Areas', '', {+ EntityType.AREA,+ })+ AUDIO_VISUAL = ( 'Audio/Visual', '', {+ EntityType.AV_RECEIVER,+ EntityType.SPEAKER,+ EntityType.SPEAKER_WIRE,+ EntityType.TELEVISION,+ })+ AUTO = ( 'Auto', '', {+ EntityType.AUTOMOBILE,+ })+ CLIMATE = ( 'Climate', '', {+ EntityType.BAROMETER,+ EntityType.CONTROL_WIRE,+ EntityType.EXHAUST_FAN,+ EntityType.HUMIDIFIER,+ EntityType.HVAC_AIR_HANDLER,+ EntityType.HVAC_CONDENSER,+ EntityType.HVAC_FURNACE,+ EntityType.HVAC_MINI_SPLIT,+ EntityType.HYGROMETER,+ EntityType.THERMOMETER,+ EntityType.THERMOSTAT,+ })+ COMPUTER_NETWORK = ( 'Computer/Network', '', {+ EntityType.ACCESS_POINT,+ EntityType.COMPUTER,+ EntityType.DISK,+ EntityType.HEALTHCHECK,+ EntityType.MODEM,+ EntityType.NETWORK_SWITCH,+ EntityType.PRINTER,+ EntityType.SERVER,+ EntityType.SERVICE,+ })+ CONSUMABLES = ( 'Consumable', '', {+ EntityType.CONSUMABLE,+ })+ FIXTURES = ( 'Fixtures', '', {+ EntityType.ATTIC_STAIRS,+ EntityType.CEILING_FAN,+ EntityType.FURNITURE,+ EntityType.SHOWER,+ EntityType.SINK,+ EntityType.TOILET,+ })+ LIGHTS_SWITCHES = ( 'Lights, Switches, Outlets', '', {+ EntityType.ELECTRICAL_OUTLET,+ EntityType.LIGHT,+ EntityType.ON_OFF_SWITCH,+ EntityType.WALL_SWITCH,+ })+ OTHER = ( 'Other', '', {+ EntityType.OTHER,+ })+ OUTDOORS = ( 'Outdoors', '', {+ EntityType.CONTROLLER,+ EntityType.GREENHOUSE,+ EntityType.MOTOR,+ EntityType.PIPE,+ EntityType.PLANT,+ EntityType.POOL_FILTER,+ EntityType.PUMP,+ EntityType.SHED,+ EntityType.SPRINKLER_HEAD,+ EntityType.SPRINKLER_VALVE,+ EntityType.SPRINKLER_WIRE,+ EntityType.TREE,+ })+ SECURITY = ( 'Security', '', {+ EntityType.CAMERA,+ EntityType.DOOR_LOCK,+ EntityType.LIGHT_SENSOR,+ EntityType.MOTION_SENSOR,+ EntityType.OPEN_CLOSE_SENSOR,+ EntityType.PRESENCE_SENSOR,+ })+ STRUCTURAL = ( 'Structural', '', {+ EntityType.DOOR,+ EntityType.FIREPLACE,+ EntityType.SKYLIGHT,+ EntityType.WINDOW,+ EntityType.WALL,+ })+ TIME_WEATHER = ( 'Time/Weather', '', {+ EntityType.TIME_SOURCE,+ EntityType.WEATHER_STATION,+ })+ TOOLS = ( 'Tools', '', {+ EntityType.TOOL,+ })+ UTILITIES = ( 'Utilities', '', {+ EntityType.ELECTRICITY_METER,+ EntityType.ELECTRIC_PANEL,+ EntityType.ELECTRIC_WIRE,+ EntityType.SEWER_LINE,+ EntityType.TELECOM_BOX,+ EntityType.TELECOM_WIRE,+ EntityType.WATER_LINE,+ EntityType.WATER_METER,+ EntityType.WATER_SHUTOFF_VALVE,+ })++ def __init__( self,+ label : str,+ description : str,+ entity_type_set : Set[ EntityType ] ):+ super().__init__( label, description )+ self.entity_type_set = entity_type_set+ return++ @classmethod+ def default(cls):+ return cls.OTHER++ @classmethod+ def from_entity_type( cls, entity_type : EntityType ):+ for entity_group_type in cls:+ if entity_type in entity_group_type.entity_type_set:+ return entity_group_type+ continue+ return cls.default()+diff --git a/src/hi/apps/entity/templates/entity/edit/modals/principal_manage.html b/src/hi/apps/entity/templates/entity/edit/modals/principal_manage.htmlindex 21f1eaad..bdd56a00 100644--- a/src/hi/apps/entity/templates/entity/edit/modals/principal_manage.html+++ b/src/hi/apps/entity/templates/entity/edit/modals/principal_manage.html@@ -17,7 +17,7 @@ Principal Add{% for entity_view_group in entity_view_group_list %}<div class="">- <div class="h5">{{ entity_view_group.entity_type.label }}</div>+ <div class="h5">{{ entity_view_group.entity_group_type.label }}</div>{% for entity_view_item in entity_view_group.item_list %}<div><input type="checkbox"diff --git a/src/hi/apps/entity/transient_models.py b/src/hi/apps/entity/transient_models.pyindex 4e9ad0e3..fda961d5 100644--- a/src/hi/apps/entity/transient_models.py+++ b/src/hi/apps/entity/transient_models.py@@ -5,7 +5,7 @@ from hi.apps.control.models import Controller, ControllerHistoryfrom hi.apps.entity.edit.forms import EntityPositionFormfrom hi.apps.sense.models import Sensor, SensorHistory-from .enums import EntityType, EntityPairingType+from .enums import EntityGroupType, EntityPairingTypefrom .forms import (EntityAttributeFormSet,EntityForm,@@ -25,8 +25,8 @@ class EntityViewItem:class EntityViewGroup:"""All entities of a given type and flagged as in the view or not."""- entity_type : EntityType- item_list : List[EntityViewItem] = field( default_factory = list )+ entity_group_type : EntityGroupType+ item_list : List[EntityViewItem] = field( default_factory = list )@dataclassdiff --git a/src/hi/apps/location/templates/location/edit/panes/location_view_manage_items.html b/src/hi/apps/location/templates/location/edit/panes/location_view_manage_items.htmlindex 4f18ad33..0ebc24c8 100644--- a/src/hi/apps/location/templates/location/edit/panes/location_view_manage_items.html+++ b/src/hi/apps/location/templates/location/edit/panes/location_view_manage_items.html@@ -16,7 +16,7 @@{% for entity_view_group in entity_view_group_list %}<div>- <div class="h5">{{ entity_view_group.entity_type.label }}</div>+ <div class="h5">{{ entity_view_group.entity_group_type.label }}</div>{% for entity_view_item in entity_view_group.item_list %}{% include "location/edit/panes/location_view_entity_toggle.html" with location_view=location_view entity=entity_view_item.entity exists_in_view=entity_view_item.exists_in_view %}{% endfor %}diff --git a/src/hi/hi_styles.py b/src/hi/hi_styles.pyindex ac0e9f10..3ba69066 100644--- a/src/hi/hi_styles.py+++ b/src/hi/hi_styles.py@@ -390,7 +390,7 @@ class StatusStyle:DEFAULT_STATUS_VALUE = ''DEFAULT_STROKE_COLOR = '#a0a0a0'- DEFAULT_STROKE_WIDTH = 4.0+ DEFAULT_STROKE_WIDTH = 2.0DEFAULT_STROKE_DASHARRAY = []DEFAULT_FILL_COLOR = 'white'DEFAULT_FILL_OPACITY = 0.0diff --git a/src/hi/services/hass/hass_converter.py b/src/hi/services/hass/hass_converter.pyindex dacb71c0..b9845109 100644--- a/src/hi/services/hass/hass_converter.py+++ b/src/hi/services/hass/hass_converter.py@@ -641,7 +641,7 @@ class HassConverter:def hass_device_to_entity_type( cls, hass_device : HassDevice ) -> EntityType:prefix_set = hass_device.entity_id_prefix_setdevice_class_set = hass_device.device_class_set-+if HassApi.CAMERA_ID_PREFIX in prefix_set:return EntityType.CAMERAif HassApi.WEATHER_ID_PREFIX in prefix_set:@@ -662,7 +662,7 @@ class HassConverter:return EntityType.THERMOSTATif HassApi.CONNECTIVITY_DEVICE_CLASS in device_class_set:return EntityType.HEALTHCHECK-+return EntityType.OTHER@classmethoddiff --git a/src/hi/static/js/svg-location.js b/src/hi/static/js/svg-location.jsindex 4d04a74f..427b62f0 100644--- a/src/hi/static/js/svg-location.js+++ b/src/hi/static/js/svg-location.js@@ -36,6 +36,7 @@const PIXEL_MOVE_DISTANCE_SCALE_FACTOR = 500.0;const ZOOM_SCALE_FACTOR_PERCENT = 10.0;+ const LOCATION_VIEW_EDIT_PANE_SELECTOR = '#hi-location-view-edit';const API_EDIT_LOCATION_VIEW_GEOMETRY_URL = '/location/edit/location-view/geometry';const SvgTransformType = {@@ -529,21 +530,21 @@}/* We decided that automatically saving the location view geometry- after move/scale/rotate was more inconvenient than helpful.- While editing, it is often useful to manipulate the location- view geometry while editing and arranging the entities. If- these entity refinements happen after the the desired geometry- has been set, then the act of editing those entities and- manipulating the location view will result in undoing the- original geometry work. Further, the user only finds this out- after they exit editing mode and see that it has changed. Thus,- we changed to require an explicit geometry save (via side panel- form). We now short circuit this function but leave the- original code below in case we are wrong about this or if- there are specific circumstances in which auto-saving is desired.+ after all move/scale/rotate operations was more inconvenient+ than helpful. While editing, it is often useful to manipulate+ the location view geometry while editing and arranging the+ entities. If these entity refinements happen after the the+ desired geometry has been set, then the act of editing those+ entities and manipulating the location view will result in+ undoing the original geometry work. Further, the user only finds+ this out after they exit editing mode and see that it has+ changed. Thus, we changed to require an explicit the location+ editing view pane to be visible.*/- return;-++ if ( $(LOCATION_VIEW_EDIT_PANE_SELECTOR).length < 1 ) {+ return;+ }if ( Hi.DEBUG ) { console.log( `Saving SVG geometry [${MODULE_NAME}]` ); }let locationViewId = $(gSelectedLocationViewSvg).attr('location-view-id');