Home Information - Your home, your data, organized.
Python
Converging on initial data model. WIP
Anthony Cassandraf72711b97bd6
diff --git a/src/hi/apps/collection/admin.py b/src/hi/apps/collection/admin.pyindex b12cbc57..6e28643e 100644--- a/src/hi/apps/collection/admin.py+++ b/src/hi/apps/collection/admin.py@@ -1,16 +1,10 @@from django.contrib import admin-from .models import Collection, CollectionEntityRelation+from .models import Collection-class CollectionEntityRelationInline(admin.TabularInline):- model = CollectionEntityRelation- extra = 1 # Number of empty forms to display in the inline--@admin.register(Collection)class CollectionAdmin(admin.ModelAdmin):- inlines = [ CollectionEntityRelationInline ]list_display = ('name',)search_fields = ('name',)ordering = ('name',)diff --git a/src/hi/apps/collection/enums.py b/src/hi/apps/collection/enums.pyindex 228e1618..84865f30 100644--- a/src/hi/apps/collection/enums.py+++ b/src/hi/apps/collection/enums.py@@ -3,6 +3,6 @@ from hi.apps.common.enums import LabeledEnumclass CollectionType(LabeledEnum):- LIST = ( 'List', '' )--+ AD_HOC = ( 'Ad-hoc', '' )+ CONTROL = ( 'Control', '' )+ AREA = ( 'Area', '' )diff --git a/src/hi/apps/collection/models.py b/src/hi/apps/collection/models.pyindex 9d23905b..7d36bb5c 100644--- a/src/hi/apps/collection/models.py+++ b/src/hi/apps/collection/models.py@@ -11,17 +11,19 @@ class Collection( models.Model ):'Name',max_length = 64)- entities = models.ManyToManyField(- Entity,- through = 'CollectionEntityRelation',- related_name = 'collections'-- )collection_type_str = models.CharField('Collection Type',max_length = 32,null = False, blank = False,)+ svg_path = models.TextField(+ 'Path',+ null = True, blank = True,+ )+ created_datetime = models.DateTimeField(+ 'Created',+ auto_now_add = True,+ )class Meta:verbose_name = 'Collection'@@ -37,25 +39,30 @@ class Collection( models.Model ):return-class CollectionEntityRelation(models.Model):+class CollectionEntity(models.Model):- entity = models.ForeignKey(- Entity,- verbose_name = 'Entity',- on_delete=models.CASCADE,- )collection = models.ForeignKey(Collection,verbose_name = 'Collection',on_delete=models.CASCADE,)+ entity = models.ForeignKey(+ Entity,+ verbose_name = 'Entity',+ on_delete=models.CASCADE,+ )order_id = models.PositiveIntegerField('Order Id',default = 0,)+ created_datetime = models.DateTimeField(+ 'Created',+ auto_now_add = True,+ )class Meta:ordering = [ 'order_id' ]indexes = [- models.Index( fields=['entity', 'collection' ] ),+ models.Index( fields=[ 'collection', 'entity' ] ),]+diff --git a/src/hi/apps/control/enums.py b/src/hi/apps/control/enums.pyindex cf1e1cdf..1d877706 100644--- a/src/hi/apps/control/enums.py+++ b/src/hi/apps/control/enums.py@@ -3,40 +3,4 @@ from hi.apps.common.enums import LabeledEnumclass ControllerType(LabeledEnum):- # !!!! Some of these should change to be view concerns, not model concerns---- SWITCH = ( 'Switch', '' ) # Boolean on/off value- SET_STRING = ( 'Set Value', '' ) # Generic, discrete value control- SET_INTEGER = ( 'Set Value', '' ) # Generic, discrete value control- SLIDER = ( 'Slider', '' ) # Continuous value control- BLOB = ( 'Blob', '' ) # For custom or large chunks of text---- # ???? !!!! There's another concept / division in here (general v. specific)- # ControllerState ControllerAction?- # Is there value in having predefined ones for convenience?---- HEATER = ( 'Heater', '' ) # Controls area- AIR_CONDITIONER = ( 'Air_Conditioner', '' ) # Controls area- HUMIDIFIER = ( 'Humidifier', '' ) # Controls area- SPINKLER_VALVE = ( 'Spinkler Valve', '' ) # Controls sprinkler heads- DOOR_LOCK = ( 'Door Lock', '' ) # Controls doors- AUDIO_AMPLIFIER = ( 'Audio Amplifier', '' ) # Controls SPeaker---class ControlledAreaType(LabeledEnum):-- LIGHT = ( 'Light', '' )- SOUND = ( 'Sound', '' )- TEMPERATURE = ( 'Temperature', '' )- HUMIDITY = ( 'Humidity', '' )- IRRIGATION = ( 'Irrigation', '' )-- @property- def svg_path_style(self):- raise NotImplementedError()+ DEFAULT = ( 'Default', '' ) # EntityState will define behaviordiff --git a/src/hi/apps/control/models.py b/src/hi/apps/control/models.pyindex 5537c844..0e19b2a3 100644--- a/src/hi/apps/control/models.py+++ b/src/hi/apps/control/models.py@@ -1,16 +1,14 @@from django.db import models-from hi.apps.device.models import DeviceState+from hi.apps.entity.models import Entity, EntityState-from .enums import ControllerType, ControlledAreaType+from .enums import ControllerTypeclass Controller( models.Model ):"""- Represents an action that can be taken.- - Will control zero or more Entities- - When controling multiple entities, it is a single action that is broadcast to all.- - The ControllerType implies what types of entities are typically controlled.+ - Will control exactly one EntityState"""name = models.CharField(@@ -18,10 +16,10 @@ class Controller( models.Model ):max_length = 64,null = False, blank = False,)- device_state = models.ForeignKey(- DeviceState,+ entity_state = models.ForeignKey(+ EntityState,related_name = 'controllers',- verbose_name = 'Device State',+ verbose_name = 'Entity State',on_delete=models.CASCADE,)controller_type_str = models.CharField(@@ -43,71 +41,40 @@ class Controller( models.Model ):self.controller_type_str = str(controller_type)return++class ControlledEntity( models.Model ):+ """The Entity associated with a Controller's state is implicitly a+ "controlled" entity, but this may also be controlling (directly or+ indirectly) the state of more than one entity.-# !!!! This is not a thing anymore: either controlling its own state ot that of an area or other device as defined by relationsnhip of state variable.--class ControlledEntity(models.Model):+ e.g., A light switch's on/off state is controlling the state of the+ switch, but also indirectly controlling the state of the light bulb.+ e.g., A sprinkler controller's on/off state for a zone is indirectly+ controlling a sprinkler valve as well as the sprinkler heads in that+ zone.+ """controller = models.ForeignKey(Controller,- related_name = 'controlled_entities',+ related_name = '+',verbose_name = 'Controller',on_delete=models.CASCADE,)- controlled_entity = models.ForeignKey(+ entity = models.ForeignKey(Entity,- related_name = 'control_sources',- verbose_name = 'Controlled Entity',+ related_name = 'controlled_by',+ verbose_name = 'Entity',on_delete=models.CASCADE,)+ created_datetime = models.DateTimeField(+ 'Created',+ auto_now_add = True,+ )class Meta:verbose_name = 'Controlled Entity'verbose_name_plural = 'Controlled Entities'--# !!! Not a thing anymore: state variables this controls are related to areas-class ControlledArea(models.Model):- """For controls that exert influence over an area. The SVG styling will- come from the ControlledAreaType.-- """---- # ???? !!! Not needed if an entity can be an Area?---- control = models.ForeignKey(- Entity,- related_name = 'controlled_areas',- verbose_name = 'Control',- on_delete=models.CASCADE,- )- svg_path = models.TextField(- 'Path',- null = False, blank = False,- )- controlled_area_type_str = models.CharField(- 'Control Area Type',- max_length = 32,- null = False, blank = False,- )-- class Meta:- verbose_name = 'Controlled Area'- verbose_name_plural = 'Controlled Areas'-- @property- def controlled_area_type(self):- return ControlledAreaType.from_name_safe( self.controlled_area_type_str )-- @controlled_area_type.setter- def controlled_area_type( self, controlled_area_type : ControlledAreaType ):- self.controlled_area_type_str = str(controlled_area_type)- return-class ControllerHistory(models.Model):@@ -125,3 +92,7 @@ class ControllerHistory(models.Model):'Created',auto_now_add = True,)++ class Meta:+ verbose_name = 'Controller History'+ verbose_name_plural = 'Controller History'diff --git a/src/hi/apps/device/models.py b/src/hi/apps/device/models.pydeleted file mode 100644index d744fcca..00000000--- a/src/hi/apps/device/models.py+++ /dev/null@@ -1,230 +0,0 @@-from django.db import models--from hi.apps.location.models import Location--from .enums import (- DeviceType,- DeviceStateType,- AttributeValueType,- AttributeSourceType,-)---class Device( models.Model ):- """- - A physical or software artifact.- - May have a fixed physical location or can just be part of a collection.- - Maybe be located at a specific point or defined by an SVG path (e.g., wire runs, areas)- - Contains zero or more sensors- - Contains zero or more controllers- - May be controlled by zero or more controllers- - It may have zero or more DeviceStates.- - The state's actual value is always hidden.- - A state may have zero of more sensors to report the state values.- - Each sensor reports the value for a single state.- - Each sensors reports state from a space of discrete or continuous values (or a blob).- - Its 'DeviceType' determines is visual appearance.- - An device can have zero or more staticly defined attributes (for information and configuration)- """-- location = models.ForeignKey(- Location,- related_name = 'devices',- verbose_name = 'Location',- on_delete = models.CASCADE,- null = False, blank = False,- )- name = models.CharField(- 'Name',- max_length = 64,- null = False, blank = False,- )- device_type_str = models.CharField(- 'Device Type',- max_length = 32,- null = False, blank = False,- )- created_datetime = models.DateTimeField(- 'Created',- auto_now_add = True,- )- updated_datetime = models.DateTimeField(- 'Updated',- auto_now=True,- blank = True,- )-- class Meta:- verbose_name = 'Device'- verbose_name_plural = 'Devices'-- @property- def device_type(self):- return DeviceType.from_name_safe( self.device_type_str )-- @device_type.setter- def device_type( self, device_type : DeviceType ):- self.device_type_str = str(device_type)- return--class DeviceState(models.Model):--- # !!! Consider how to model an area with multiple temp sensors and multiple controllers to alter the temp.-- device = models.ForeignKey(- Device,- related_name = 'states',- verbose_name = 'Device',- on_delete=models.CASCADE,- )- name = models.CharField(- 'Name',- max_length = 64,- null = False, blank = False,- )- device_state_type_str = models.CharField(- 'Device State Type',- max_length = 32,- null = False, blank = False,- )-- class Meta:- verbose_name = 'DeviceState'- verbose_name_plural = 'DeviceStates'-- @property- def device_state_type(self):- return DeviceStateType.from_name_safe( self.device_state_type_str )-- @device_state_type.setter- def device_state_type( self, device_state_type : DeviceStateType ):- self.device_state_type_str = str(device_state_type)- return----class DevicePosition(models.Model):- """For devices represented by an icon. This is the most common case. The- icon and its styling determined by the DeviceType. An Device is not- required to have an DevicePosition.-- """-- device = models.OneToOneField(- Device,- related_name = 'position',- verbose_name = 'Device',- on_delete = models.CASCADE,- )- svg_x = models.DecimalField(- 'X',- max_digits = 12,- decimal_places = 6,- )- svg_y = models.DecimalField(- 'Y',- max_digits = 12,- decimal_places = 6,- )- svg_scale = models.DecimalField(- 'Scale',- max_digits = 12,- decimal_places = 6,- default = 1.0,- )- svg_rotation = models.DecimalField(- 'Rotation',- max_digits = 12,- decimal_places = 6,- default = 0.0,- )-- class Meta:- verbose_name = 'DevicePosition'- verbose_name_plural = 'DevicePositionss'---class DevicePath(models.Model):- """For devices represented by an arbitary SVG path. e.g., The path of a- utility line, The styling of the path is determined by the DeviceType. An Device is not- required to have an DevicePath.-- """-- device = models.OneToOneField(- Device,- related_name = 'path',- verbose_name = 'Device',- on_delete = models.CASCADE,- )- svg_path = models.TextField(- 'Path',- null = False, blank = False,- )-- class Meta:- verbose_name = 'DevicePath'- verbose_name_plural = 'DevicePaths'---class Attribute(models.Model):- """- Information related to an device, e.g., specs, docs, notes, configs)- """-- device = models.ForeignKey(- Device,- related_name = 'attributes',- verbose_name = 'Device',- on_delete=models.CASCADE,- )- attribute_value_type_str = models.CharField(- 'Attribute Value Type',- max_length = 32,- null = False, blank = False,- )- name = models.CharField(- 'Name',- max_length = 64,- )- value = models.CharField(- 'Value',- max_length = 255- )- attribute_source_type_str = models.CharField(- 'Attribute Source Type',- max_length = 32,- null = False, blank = False,- )- is_editable = models.BooleanField(- 'Editable?',- default = True,- )- is_required = models.BooleanField(- 'Required?',- default = False,- )-- class Meta:- verbose_name = 'Attribute'- verbose_name_plural = 'Attributes'-- @property- def attribute_value_type(self):- return AttributeValueType.from_name_safe( self.attribute_value_type_str )-- @attribute_value_type.setter- def attribute_value_type( self, attribute_value_type : AttributeValueType ):- self.attribute_value_type_str = str(attribute_value_type)- return-- @property- def attribute_source_type(self):- return AttributeSourceType.from_name_safe( self.attribute_source_type_str )-- @attribute_source_type.setter- def attribute_source_type( self, attribute_source_type : AttributeSourceType ):- self.attribute_source_type_str = str(attribute_source_type)- return-diff --git a/src/hi/apps/device/__init__.py b/src/hi/apps/entity/__init__.pysimilarity index 100%rename from src/hi/apps/device/__init__.pyrename to src/hi/apps/entity/__init__.pydiff --git a/src/hi/apps/device/admin.py b/src/hi/apps/entity/admin.pysimilarity index 100%rename from src/hi/apps/device/admin.pyrename to src/hi/apps/entity/admin.pydiff --git a/src/hi/apps/device/apps.py b/src/hi/apps/entity/apps.pysimilarity index 81%rename from src/hi/apps/device/apps.pyrename to src/hi/apps/entity/apps.pyindex 529f81ed..7679e85f 100644--- a/src/hi/apps/device/apps.py+++ b/src/hi/apps/entity/apps.py@@ -3,4 +3,4 @@ from django.apps import AppConfigclass DeviceConfig(AppConfig):default_auto_field = "django.db.models.BigAutoField"- name = "hi.apps.device"+ name = "hi.apps.entity"diff --git a/src/hi/apps/device/enums.py b/src/hi/apps/entity/enums.pysimilarity index 57%rename from src/hi/apps/device/enums.pyrename to src/hi/apps/entity/enums.pyindex e00b67d7..06d10794 100644--- a/src/hi/apps/device/enums.py+++ b/src/hi/apps/entity/enums.py@@ -1,16 +1,16 @@from hi.apps.common.enums import LabeledEnum-class DeviceType(LabeledEnum):-+class EntityType(LabeledEnum):"""- SVG File needed for each (by convention): templates/device/svg/{name.lower()}.svg+ - SVG File needed for each of these, else uses default.+ - SVG filename is by convention: templates/entity/svg/type.{name.lower()}.svg"""- AIR_CONDITIONER = ( 'Air_Conditioner', '' ) # Controls area+ AIR_CONDITIONER = ( 'Air Conditioner', '' ) # Controls areaAPPLIANCE = ( 'Appliance', '' )AREA = ( 'Area', '' )- AUDIO_AMPLIFIER = ( 'Audio Amplifier', '' ) # Controls SPeaker+ AUDIO_AMPLIFIER = ( 'Audio Amplifier', '' ) # Controls SpeakerAUDIO_PLAYER = ( 'Audio Player', '' )BAROMETER = ( 'Barometer', '' )CAMERA = ( 'Camera', '' )@@ -21,18 +21,23 @@ class DeviceType(LabeledEnum):DOOR_LOCK = ( 'Door Lock', '' ) # Controls doorsELECTRICAL_OUTLET = ( 'Electrical Outlet', '' )ELECTRICY_METER = ( 'Electric Meter', '' )- ELECTRIC_PANEL = ( 'Electric_Panel', '' )+ ELECTRIC_PANEL = ( 'Electric Panel', '' )ELECTRIC_WIRE = ( 'Electric Wire', '' )HEATER = ( 'Heater', '' ) # Controls area+ HVAC_AIR_HANDLER = ( 'HVAC Air Handler', '' ) # Controls area+ HVAC_CONDENSER = ( 'HVAC Condenser', '' ) # Controls area+ HVAC_MIN_SPLIT = ( 'HVAC Mini-split', '' ) # Controls areaHUMIDIFIER = ( 'Humidifier', '' ) # Controls areaHYGROMETER = ( 'Hygrometer', '' )LIGHT = ( 'Light', '' )LIGHT_SENSOR = ( 'Light Sensor', '' )MOTION_SENSOR = ( 'Motion Sensor', '' )- OPEN_CLOSE_DETECTOR = ( 'Open/Close_Sensor', '' )+ OPEN_CLOSE_DETECTOR = ( 'Open/Close Sensor', '' )OTHER = ( 'Other', '' )PRESENCE_SENSOR = ( 'Presence Sensor', '' )SEWER_LINE = ( 'Sewer Wire', '' )+ SHOWER = ( 'Shower', '' )+ SINK = ( 'Sink', '' )SPEAKER = ( 'Speaker', '' )SPINKLER_CONTROLLER = ( 'Spinkler Controller', '' )SPINKLER_VALVE = ( 'Spinkler Valve', '' ) # Controls sprinkler heads@@ -41,11 +46,14 @@ class DeviceType(LabeledEnum):TELECOM_WIRE = ( 'Telecom Wire', '' )THERMOMETER = ( 'Thermometer', '' )THERMOSTAT = ( 'Thermostat', '' )+ TOILET = ( 'Toilet', '' )TOOL = ( 'Tool', '' )VIDEO_PLAYER = ( 'Video Player', '' )WALL_SWITCH = ( 'Wall Switch', '' )+ WASTE_PIPE = ( 'Waste Pipe', '' )+ WATER_HEATER = ( 'Water Heater', '' )WATER_LINE = ( 'Water Line', '' )- WATER_METER = ( 'Water_Meter', '' )+ WATER_METER = ( 'Water Meter', '' )WATER_SHUTOFF_VALVE = ( 'Water Shutoff Valve', '' )WEATHER_STATION = ( 'Weather Station', '' )@@ -58,19 +66,37 @@ class DeviceType(LabeledEnum):raise NotImplementedError()-class DeviceStateType(LabeledEnum):+class EntityStateType(LabeledEnum):- DICRETE = ( 'Dicrete', '' )- CONTINUOUS = ( 'Continuous', '' )- BLOB = ( 'Blob', '' )- MOVEMENT = ( 'Movement', '' )-- TEMPERATURE = ( 'Temperature', '' )- HUMIDITY = ( 'Humidity', '' )- LIGHT_LEVEL = ( 'Light Level', '' )- SOUND_LEVEL = ( 'Sound Level', '' )- MOISTURE = ( 'Moisture', '' )- WIND_SPEED = ( 'Wind Speed', '' )+ # General types+ DICRETE = ( 'Dicrete', '' )+ CONTINUOUS = ( 'Continuous', '' )+ BLOB = ( 'Blob', '' )++ # Specific types+ AIR_PRESSURE = ( 'Air Pressure', '' )+ BANDWIDTH_USAGE = ( 'Bandwidth Usage', '' )+ CONNECTION = ( 'Connection', '' )+ ELECTRIC_USAGE = ( 'Electric Usage', '' )+ HUMIDITY = ( 'Humidity', '' )+ VIDEO_STREAM = ( 'Video Stream', '' )+ LIGHT_LEVEL = ( 'Light Level', '' )+ MOISTURE = ( 'Moisture', '' )+ MOVEMENT = ( 'Movement', '' )+ NOISE_LEVEL = ( 'Noise Level', '' )+ ON_OFF = ( 'On/Off', '' )+ OPEN_CLOSE = ( 'Open/Close', '' )+ PRESENCE = ( 'Presence', '' )+ SOUND_LEVEL = ( 'Sound Level', '' )+ TEMPERATURE = ( 'Temperature', '' )+ WATER_FLOW = ( 'Water Flow', '' )+ WIND_SPEED = ( 'Wind Speed', '' )+++class AttributeType(LabeledEnum):++ PREDEFINED = ('Predefined', '' )+ CUSTOM = ('Custom', '' )class AttributeValueType(LabeledEnum):@@ -86,7 +112,7 @@ class AttributeValueType(LabeledEnum):LINK = ('Link', '' )-class AttributeSourceType(LabeledEnum):-- PREDEFINED = ('Predefined', '' )- CUSTOM = ('Custom', '' )+class AttributeName(LabeledEnum):+ # Common attribute names++ INTEGRATION_SOURCE = ( 'Integration Source', '' )diff --git a/src/hi/apps/device/migrations/__init__.py b/src/hi/apps/entity/migrations/__init__.pysimilarity index 100%rename from src/hi/apps/device/migrations/__init__.pyrename to src/hi/apps/entity/migrations/__init__.pydiff --git a/src/hi/apps/entity/models.py b/src/hi/apps/entity/models.pynew file mode 100644index 00000000..6fe9b164--- /dev/null+++ b/src/hi/apps/entity/models.py@@ -0,0 +1,274 @@+from django.db import models++from hi.apps.location.models import Location++from .enums import (+ EntityType,+ EntityStateType,+ AttributeValueType,+ AttributeType,+)+++class Entity( models.Model ):+ """+ - A physical feature, device or software artifact.+ - May have a fixed physical location (or can just be part of a collection)+ - Maybe be located at a specific point or defined by an SVG path (e.g., paths for wire, pipes, etc.)+ - It may have zero or more EntityStates.+ - The entity state values are always hidden.+ - A state may have zero of more sensors to report the state values.+ - Each sensor reports the value for a single state.+ - Each sensors reports state from a space of discrete or continuous values (or a blob).+ - A state may have zero or more controllers.+ - Each controller may control+ - Its 'EntityType' determines is visual appearance.+ - An entity can have zero or more staticly defined attributes (for information and configuration)+ """++ name = models.CharField(+ 'Name',+ max_length = 64,+ null = False, blank = False,+ )+ entity_type_str = models.CharField(+ 'Type',+ max_length = 32,+ null = False, blank = False,+ )+ created_datetime = models.DateTimeField(+ 'Created',+ auto_now_add = True,+ )++ class Meta:+ verbose_name = 'Entity'+ verbose_name_plural = 'Entities'++ @property+ def entity_type(self):+ return EntityType.from_name_safe( self.entity_type_str )++ @entity_type.setter+ def entity_type( self, entity_type : EntityType ):+ self.entity_type_str = str(entity_type)+ return+++class EntityState(models.Model):+ """+ - The (hidden) state of an entity that can be controlled and/or sensed.+ - The EntityType will help define the (default) name and value ranges (if not a general type)+ """++ entity = models.ForeignKey(+ Entity,+ related_name = 'states',+ verbose_name = 'Entity',+ on_delete=models.CASCADE,+ )+ entity_state_type_str = models.CharField(+ 'State Type',+ max_length = 32,+ null = False, blank = False,+ )+ name = models.CharField(+ 'Name',+ max_length = 64,+ null = False, blank = False,+ )+ value_range = models.TextField(+ 'Value Range',+ null = False, blank = False,+ )+ units = models.CharField(+ 'Units',+ max_length = 32,+ null = True, blank = True,+ )+ created_datetime = models.DateTimeField(+ 'Created',+ auto_now_add = True,+ )++ class Meta:+ verbose_name = 'Entity State'+ verbose_name_plural = 'Entity States'++ @property+ def entity_state_type(self):+ return EntityStateType.from_name_safe( self.entity_state_type_str )++ @entity_state_type.setter+ def entity_state_type( self, entity_state_type : EntityStateType ):+ self.entity_state_type_str = str(entity_state_type)+ return+++class EntityPosition(models.Model):+ """+ - For entities represented by an SVG icon.+ - This is the most common case.+ - The icon and its styling determined by the EntityType.+ - An Entity is not required to have an EntityPosition.+ """++ location = models.ForeignKey(+ Location,+ related_name = 'positions',+ verbose_name = 'Location',+ on_delete = models.CASCADE,+ null = False, blank = False,+ )+ entity = models.ForeignKey(+ Entity,+ related_name = 'positions',+ verbose_name = 'Entity',+ on_delete = models.CASCADE,+ )+ svg_x = models.DecimalField(+ 'X',+ max_digits = 12,+ decimal_places = 6,+ )+ svg_y = models.DecimalField(+ 'Y',+ max_digits = 12,+ decimal_places = 6,+ )+ svg_scale = models.DecimalField(+ 'Scale',+ max_digits = 12,+ decimal_places = 6,+ default = 1.0,+ )+ svg_rotation = models.DecimalField(+ 'Rotation',+ max_digits = 12,+ decimal_places = 6,+ default = 0.0,+ )+ created_datetime = models.DateTimeField(+ 'Created',+ auto_now_add = True,+ )+ updated_datetime = models.DateTimeField(+ 'Updated',+ auto_now=True,+ blank = True,+ )++ class Meta:+ verbose_name = 'Entity Position'+ verbose_name_plural = 'Entity Positions'+ indexes = [+ models.Index( fields=[ 'location', 'entity' ] ),+ ]+++class EntityPath(models.Model):+ """+ - For entities represented by an arbitary SVG path. e.g., The path of a utility line,+ - The styling of the path is determined by the EntityType.+ - An Entity is not required to have an EntityPath.+ """++ location = models.ForeignKey(+ Location,+ related_name = 'paths',+ verbose_name = 'Location',+ on_delete = models.CASCADE,+ null = False, blank = False,+ )+ entity = models.ForeignKey(+ Entity,+ related_name = 'paths',+ verbose_name = 'Entity',+ on_delete = models.CASCADE,+ )+ svg_path = models.TextField(+ 'Path',+ null = False, blank = False,+ )+ created_datetime = models.DateTimeField(+ 'Created',+ auto_now_add = True,+ )++ class Meta:+ verbose_name = 'Entity Path'+ verbose_name_plural = 'Entity Paths'+ indexes = [+ models.Index( fields=[ 'location', 'entity' ] ),+ ]+++class Attribute(models.Model):+ """+ - Information related to an entity, e.g., specs, docs, notes, configs+ - The 'attribute type' is used to help define what information the user might need to provide.+ """++ entity = models.ForeignKey(+ Entity,+ related_name = 'attributes',+ verbose_name = 'Entity',+ on_delete=models.CASCADE,+ )+ attribute_value_type_str = models.CharField(+ 'Attribute Value Type',+ max_length = 32,+ null = False, blank = False,+ )+ name = models.CharField(+ 'Name',+ max_length = 64,+ )+ value = models.TextField(+ 'Value',+ )+ attribute_type_str = models.CharField(+ 'Attribute Type',+ max_length = 32,+ null = False, blank = False,+ )+ is_editable = models.BooleanField(+ 'Editable?',+ default = True,+ )+ is_required = models.BooleanField(+ 'Required?',+ default = False,+ )+ created_datetime = models.DateTimeField(+ 'Created',+ auto_now_add = True,+ )+ updated_datetime = models.DateTimeField(+ 'Updated',+ auto_now=True,+ blank = True,+ )++ class Meta:+ verbose_name = 'Attribute'+ verbose_name_plural = 'Attributes'++ @property+ def attribute_value_type(self):+ return AttributeValueType.from_name_safe( self.attribute_value_type_str )++ @attribute_value_type.setter+ def attribute_value_type( self, attribute_value_type : AttributeValueType ):+ self.attribute_value_type_str = str(attribute_value_type)+ return++ @property+ def attribute_type(self):+ return AttributeType.from_name_safe( self.attribute_type_str )++ @attribute_type.setter+ def attribute_type( self, attribute_type : AttributeType ):+ self.attribute_type_str = str(attribute_type)+ return+diff --git a/src/hi/apps/location/enums.py b/src/hi/apps/location/enums.pynew file mode 100644index 00000000..1cdf0252--- /dev/null+++ b/src/hi/apps/location/enums.py@@ -0,0 +1,7 @@+from hi.apps.common.enums import LabeledEnum+++class ViewType(LabeledEnum):++ CONTROL = ('Control', '' )+ INFORMATION = ('Information', '' )diff --git a/src/hi/apps/location/models.py b/src/hi/apps/location/models.pyindex 33fa8b1f..468e4a19 100644--- a/src/hi/apps/location/models.py+++ b/src/hi/apps/location/models.py@@ -1,5 +1,7 @@from django.db import models+from .enums import ViewType+class Location(models.Model):@@ -68,6 +70,11 @@ class LocationView(models.Model):on_delete = models.CASCADE,null = False, blank = False,)+ view_type_str = models.CharField(+ 'View Type',+ max_length = 32,+ null = False, blank = False,+ )name = models.CharField('Name',max_length = 64,@@ -108,3 +115,11 @@ class LocationView(models.Model):def __repr__(self):return self.__str__()+ @property+ def view_type(self):+ return ViewType.from_name_safe( self.view_type_str )++ @view_type.setter+ def view_type( self, view_type : ViewType ):+ self.view_type_str = str(view_type)+ returndiff --git a/src/hi/apps/sense/enums.py b/src/hi/apps/sense/enums.pyindex 06a8a44d..2bbc44ca 100644--- a/src/hi/apps/sense/enums.py+++ b/src/hi/apps/sense/enums.py@@ -3,40 +3,4 @@ from hi.apps.common.enums import LabeledEnumclass SensorType(LabeledEnum):- DISCRETE_VALUE = ( 'Discrete Value', '' ) # Generic for devices- CONTINUOUS_VALUE = ( 'Continuous Value', '' ) # Generic for device controls- BLOB = ( 'Blob', '' ) # For custom, large chunks of text, video streams--- # ??? !!! Are the below not needed as just specilizations for each device type?- # Is there value in having predefined ones for convenience?--- BANDWIDTH_USAGE = ( 'Bandwidth Usage', '' )- ELECTRIC_USAGE = ( 'Electric Usage', '' )- WATER_FLOW = ( 'Water Flow', '' )-- # Area Sensors- VISUAL_DYNAMIC = ( 'Visual Dynamic', '' ) # For video stream- VISUAL_STATIC = ( 'Visual Static', '' ) # For static images- MOTION = ( 'Motion', '' )- CONTACT = ( 'Contact', '' ) # For open/close or for connectivity check---class SensedAreaType(LabeledEnum):-- VISIBLE_CONTINUOUS = ( 'Visible', '' ) # Video stream- VISIBLE_DISCRETE = ( 'Visible Discrete', '' ) # Pictures/Snapshots-- MOVEMENT = ( 'Movement', '' )- PRESENCE = ( 'Presence', '' )- TEMPERATURE = ( 'Temperature', '' )- HUMIDITY = ( 'Humidity', '' )- AIR_PRESSURE = ( 'Air Pressure', '' )- LIGHT_LEVEL = ( 'Light Level', '' )- NOISE_LEVEL = ( 'Noise Level', '' )-- @property- def svg_path_style(self):- raise NotImplementedError()-+ DEFAULT = ( 'Default', '' ) # EntityState will define behaviordiff --git a/src/hi/apps/sense/models.py b/src/hi/apps/sense/models.pyindex 5725bf66..779a3180 100644--- a/src/hi/apps/sense/models.py+++ b/src/hi/apps/sense/models.py@@ -1,19 +1,14 @@from django.db import models-from hi.apps.devices.models import DeviceState+from hi.apps.entity.models import Entity, EntityState-from .enums import SensorType, SensedAreaType+from .enums import SensorTypeclass Sensor( models.Model ):"""- - Represents an observed state of an device.- - An devices state's is hidden and a sensor's value may not be true state (sensors can fail).- - May sense zero or more Entities- - When sensing multiple Entities, the sensed value is a single value, aggregated from all.- - The SensorType defines the type of sensed value.- - Sensor value are discrete, continuous or a blob a data.- - Continuous valued sensors usually have units (defined by the SensorType).+ - Represents an observed state of an entity.+ - Will sense exactly one EntityState"""name = models.CharField(@@ -21,10 +16,10 @@ class Sensor( models.Model ):max_length = 64,null = False, blank = False,)- device_state = models.ForeignKey(- DeviceState,+ entity_state = models.ForeignKey(+ EntityState,related_name = 'sensors',- verbose_name = 'Device State',+ verbose_name = 'Entity State',on_delete=models.CASCADE,)sensor_type_str = models.CharField(@@ -45,70 +40,42 @@ class Sensor( models.Model ):def sensor_type( self, sensor_type : SensorType ):self.sensor_type_str = str(sensor_type)return--# !!! Not a thing anymore: state variables this senses are related to areas+class SensedEntity(models.Model):+ """The Entity associated with a Sensors's state is implicitly a+ "sensed" entity, but this may also be sensing (directly or+ indirectly) the state of more than one entity.++ e.g., An open/close sensor is directly sensing the proximity sensor in+ the device, but it is indirectly trying to sense the state of a door or window.++ e.g., A temperature sensor might be the aggregate of a number of thermometer readings.++ """sensor = models.ForeignKey(Sensor,- related_name = 'sensed_entities',+ related_name = '+',verbose_name = 'Sensor',on_delete=models.CASCADE,)- sensed_entity = models.ForeignKey(+ entity = models.ForeignKey(Entity,- related_name = 'sense_sources',- verbose_name = 'Sensed Entity',+ related_name = 'sensed_by',+ verbose_name = 'Entity',on_delete=models.CASCADE,)+ created_datetime = models.DateTimeField(+ 'Created',+ auto_now_add = True,+ )class Meta:verbose_name = 'Sensed Entity'verbose_name_plural = 'Sensed Entities'-# !!! Not a thing anymore: state variables this senses are related to areas-class SensedArea(models.Model):- """For sensors that are detection area-wide conditions. The SVG styling- will come from the SensedAreaType.-- """--- # ???? !!! Not needed if an entity can be an Area?--- sensor = models.ForeignKey(- Entity,- related_name = 'sensed_areas',- verbose_name = 'Sensor',- on_delete=models.CASCADE,- )- svg_path = models.TextField(- 'Path',- null = False, blank = False,- )- sensed_area_type_str = models.CharField(- 'Sensed Area Type',- max_length = 32,- null = False, blank = False,- )-- class Meta:- verbose_name = 'Sensed Area'- verbose_name_plural = 'Sensed Areas'-- @property- def sensed_area_type(self):- return SensedAreaType.from_name_safe( self.sensed_area_type_str )-- @sensed_area_type.setter- def sensed_area_type( self, sensed_area_type : SensedAreaType ):- self.sensed_area_type_str = str(sensed_area_type)- return--class SensorHistory(models.Model):sensor = models.ForeignKey(@@ -126,3 +93,6 @@ class SensorHistory(models.Model):auto_now_add = True,)+ class Meta:+ verbose_name = 'Sensor History'+ verbose_name_plural = 'Sensor History'diff --git a/src/hi/settings/base.py b/src/hi/settings/base.pyindex 6e7631e3..d0c14138 100644--- a/src/hi/settings/base.py+++ b/src/hi/settings/base.py@@ -137,7 +137,7 @@ INSTALLED_APPS = ['constance','hi.apps.common','hi.apps.location',- 'hi.apps.device',+ 'hi.apps.entity','hi.apps.collection','hi.apps.sense','hi.apps.control',