Home Information - Your home, your data, organized.
Python
Saving work. WIP ... working on defining the overall data model.
Anthony Cassandra414bcaa8f043
diff --git a/src/hi/apps/collection/admin.py b/src/hi/apps/collection/admin.pyindex 0d7f2a45..b12cbc57 100644--- a/src/hi/apps/collection/admin.py+++ b/src/hi/apps/collection/admin.py@@ -1,16 +1,16 @@from django.contrib import admin-from .models import Collection, CollectionRelation+from .models import Collection, CollectionEntityRelation-class CollectionRelationInline(admin.TabularInline):- model = CollectionRelation+class CollectionEntityRelationInline(admin.TabularInline):+ model = CollectionEntityRelationextra = 1 # Number of empty forms to display in the inline@admin.register(Collection)class CollectionAdmin(admin.ModelAdmin):- inlines = [ CollectionRelationInline ]+ inlines = [ CollectionEntityRelationInline ]list_display = ('name',)search_fields = ('name',)ordering = ('name',)diff --git a/src/hi/apps/collection/models.py b/src/hi/apps/collection/models.pyindex ae2bfbf2..9d23905b 100644--- a/src/hi/apps/collection/models.py+++ b/src/hi/apps/collection/models.py@@ -13,7 +13,7 @@ class Collection( models.Model ):)entities = models.ManyToManyField(Entity,- through = 'CollectionRelation',+ through = 'CollectionEntityRelation',related_name = 'collections')@@ -37,7 +37,7 @@ class Collection( models.Model ):return-class CollectionRelation(models.Model):+class CollectionEntityRelation(models.Model):entity = models.ForeignKey(Entity,diff --git a/src/hi/apps/control/enums.py b/src/hi/apps/control/enums.pyindex 5b22bc6a..9577832d 100644--- a/src/hi/apps/control/enums.py+++ b/src/hi/apps/control/enums.py@@ -1,13 +1,35 @@from hi.apps.common.enums import LabeledEnum-class ControlType(LabeledEnum):+class ControllerType(LabeledEnum):++ SETTING = ( 'Setting', '' ) # Generic, discrete value control (incl. on/off)+ 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?- CONTINUOUS = ( 'Continuous', '' )- DISCRETE = ( 'Dicrete', '' )+++ 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 SPeakerclass ControlledAreaType(LabeledEnum):LIGHT = ( 'Light', '' )+ SOUND = ( 'Sound', '' )+ TEMPERATURE = ( 'Temperature', '' )+ HUMIDITY = ( 'Humidity', '' )IRRIGATION = ( 'Irrigation', '' )++ @property+ def svg_path_style(self):+ raise NotImplementedError()diff --git a/src/hi/apps/control/models.py b/src/hi/apps/control/models.pyindex b7187991..7d618c0d 100644--- a/src/hi/apps/control/models.py+++ b/src/hi/apps/control/models.py@@ -2,11 +2,17 @@ from django.db import modelsfrom hi.apps.entity.models import Entity-from .enums import ControlType, ControlledAreaType+from .enums import ControllerType, ControlledAreaType-class Control( models.Model ):-+class 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.+ """+name = models.CharField('Name',max_length = 64,@@ -14,41 +20,41 @@ class Control( models.Model ):)entity = models.ForeignKey(Entity,- related_name = 'controls',+ related_name = 'controllers',verbose_name = 'Entity',on_delete=models.CASCADE,)- control_type_str = models.CharField(- 'Control Type',+ controller_type_str = models.CharField(+ 'Controller Type',max_length = 32,null = False, blank = False,)class Meta:- verbose_name = 'Control'- verbose_name_plural = 'Controls'+ verbose_name = 'Controller'+ verbose_name_plural = 'Controllers'@property- def control_type(self):- return ControlType.from_name_safe( self.control_type_str )+ def controller_type(self):+ return ControllerType.from_name_safe( self.controller_type_str )- @control_type.setter- def control_type( self, control_type : ControlType ):- self.control_type_str = str(control_type)+ @controller_type.setter+ def controller_type( self, controller_type : ControllerType ):+ self.controller_type_str = str(controller_type)returnclass ControlledEntity(models.Model):- control = models.ForeignKey(- Entity,+ controller = models.ForeignKey(+ Controller,related_name = 'controlled_entities',- verbose_name = 'Control',+ verbose_name = 'Controller',on_delete=models.CASCADE,)controlled_entity = models.ForeignKey(Entity,- related_name = 'controlling_source',+ related_name = 'control_sources',verbose_name = 'Controlled Entity',on_delete=models.CASCADE,)@@ -63,6 +69,12 @@ class ControlledArea(models.Model):come from the ControlledAreaType."""++++ # ???? !!! Not needed if an entity can be an Area?++control = models.ForeignKey(Entity,@@ -90,5 +102,23 @@ class ControlledArea(models.Model):@controlled_area_type.setterdef controlled_area_type( self, controlled_area_type : ControlledAreaType ):- self.controlled_area_type_str = str(control_coverage_type)+ self.controlled_area_type_str = str(controlled_area_type)return+++class ControllerHistory(models.Model):++ controller = models.ForeignKey(+ Controller,+ related_name = 'history',+ verbose_name = 'Controller',+ on_delete=models.CASCADE,+ )+ value = models.CharField(+ 'Value',+ max_length = 255+ )+ created_datetime = models.DateTimeField(+ 'Created',+ auto_now_add = True,+ )diff --git a/src/hi/apps/entity/enums.py b/src/hi/apps/entity/enums.pyindex 1dab001f..8ab58639 100644--- a/src/hi/apps/entity/enums.py+++ b/src/hi/apps/entity/enums.py@@ -7,38 +7,56 @@ class EntityType(LabeledEnum):SVG File needed for each (by convention): templates/entity/svg/{name.lower()}.svg"""+ AIR_CONDITIONER = ( 'Air_Conditioner', '' ) # Controls area+ APPLIANCE = ( 'Appliance', '' )+ AREA = ( 'Area', '' )+ AUDIO_AMPLIFIER = ( 'Audio Amplifier', '' ) # Controls SPeaker+ AUDIO_PLAYER = ( 'Audio Player', '' )+ BAROMETER = ( 'Barometer', '' )CAMERA = ( 'Camera', '' )- MOTION_SENSOR = ( 'Motion Sensor', '' )- LIGHT_SWITCH = ( 'Light Switch', '' )- LIGHT = ( 'Light', '' )- ELECTRICAL_OUTLET = ( 'Electrical Outlet', '' )- CONTACT_SENSOR = ( 'Contact Sensor', '' )+ COMPUTER = ( 'Computer', '' )+ CONTROL_WIRE = ( 'Control Wire', '' )+ DISPLAY = ( 'Display', '' )DOOR = ( 'Door', '' )- INTERNET_CONNECTION = ( 'Internet Connection', '' )- ELECTRIC_WIRE = ( 'Electric Wire', '' )- TELECOM_WIRE = ( 'Telecom Wire', '' )- TELECOM_BOX = ( 'Telecom Box', '' )- WATER_LINE = ( 'Water Line', '' )- SEWER_LINE = ( 'Sewer Wire', '' )+ DOOR_LOCK = ( 'Door Lock', '' ) # Controls doors+ ELECTRICAL_OUTLET = ( 'Electrical Outlet', '' )+ ELECTRICY_METER = ( 'Electric Meter', '' )ELECTRIC_PANEL = ( 'Electric_Panel', '' )- WATER_SHUTOFF_VALVE = ( 'Water Shutoff Valve', '' )- WATER_METER = ( 'Water_Meter', '' )- DOOR_LOCK = ( 'Door Lock', '' )- THERMOSTAT = ( 'Thermostat', '' )- THERMOMETER = ( 'Thermometer', '' )+ ELECTRIC_WIRE = ( 'Electric Wire', '' )+ HEATER = ( 'Heater', '' ) # Controls area+ HUMIDIFIER = ( 'Humidifier', '' ) # Controls areaHYGROMETER = ( 'Hygrometer', '' )- BAROMETER = ( 'Barometer', '' )- HEATER = ( 'Heater', '' )- AIR_CONDITIONER = ( 'Air_Conditioner', '' )- HUMIDIFIER = ( 'Humidifier', '' )- COMPUTER = ( 'Computer', '' )- APPLIANCE = ( 'Appliance', '' )- TOOL = ( 'Tool', '' )- SWITCH = ( 'Switch', '' )+ LIGHT = ( 'Light', '' )+ LIGHT_SENSOR = ( 'Light Sensor', '' )+ MOTION_SENSOR = ( 'Motion Sensor', '' )+ OPEN_CLOSE_DETECTOR = ( 'Open/Close_Sensor', '' )+ OTHER = ( 'Other', '' )+ PRESENCE_SENSOR = ( 'Presence Sensor', '' )+ SEWER_LINE = ( 'Sewer Wire', '' )+ SPEAKER = ( 'Speaker', '' )SPINKLER_CONTROLLER = ( 'Spinkler Controller', '' )- SPINKLER_VALVE = ( 'Spinkler Valve', '' )+ SPINKLER_VALVE = ( 'Spinkler Valve', '' ) # Controls sprinkler headsSPRINKLER_HEAD = ( 'Sprinkler Head', '' )+ TELECOM_BOX = ( 'Telecom Box', '' )+ TELECOM_WIRE = ( 'Telecom Wire', '' )+ THERMOMETER = ( 'Thermometer', '' )+ THERMOSTAT = ( 'Thermostat', '' )+ TOOL = ( 'Tool', '' )+ VIDEO_PLAYER = ( 'Video Player', '' )+ WALL_SWITCH = ( 'Wall Switch', '' )+ WATER_LINE = ( 'Water Line', '' )+ WATER_METER = ( 'Water Meter', '' )+ WATER_METER = ( 'Water_Meter', '' )+ WATER_SHUTOFF_VALVE = ( 'Water Shutoff Valve', '' )++ @property+ def svg_icon_name(self):+ raise NotImplementedError()+ @property+ def svg_path_style(self):+ raise NotImplementedError()+class EntityAttributeType(LabeledEnum):diff --git a/src/hi/apps/entity/models.py b/src/hi/apps/entity/models.pyindex 742ea406..bb32cda6 100644--- a/src/hi/apps/entity/models.py+++ b/src/hi/apps/entity/models.py@@ -6,7 +6,22 @@ from .enums import EntityType, EntityAttributeTypeclass Entity( models.Model ):-+ """+ - A physical object or space.+ - 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 states.+ - 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 'EntityType' determines is visual appearance.+ - An entity can have zero or more staticly defined attributes (for information and configuration)+ """+location = models.ForeignKey(Location,related_name = 'entities',@@ -24,6 +39,15 @@ class Entity( models.Model ):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 = 'Entity'@@ -104,6 +128,9 @@ class EntityPath(models.Model):class EntityAttribute(models.Model):+ """+ Information related to an entity, e.g., specs, docs, notes, configs)+ """entity = models.ForeignKey(Entity,diff --git a/src/hi/apps/sensor/__init__.py b/src/hi/apps/sense/__init__.pysimilarity index 100%rename from src/hi/apps/sensor/__init__.pyrename to src/hi/apps/sense/__init__.pydiff --git a/src/hi/apps/sensor/admin.py b/src/hi/apps/sense/admin.pysimilarity index 100%rename from src/hi/apps/sensor/admin.pyrename to src/hi/apps/sense/admin.pydiff --git a/src/hi/apps/sensor/apps.py b/src/hi/apps/sense/apps.pysimilarity index 81%rename from src/hi/apps/sensor/apps.pyrename to src/hi/apps/sense/apps.pyindex a03def4c..4243a85c 100644--- a/src/hi/apps/sensor/apps.py+++ b/src/hi/apps/sense/apps.py@@ -3,4 +3,4 @@ from django.apps import AppConfigclass SensorConfig(AppConfig):default_auto_field = "django.db.models.BigAutoField"- name = "hi.apps.sensor"+ name = "hi.apps.sense"diff --git a/src/hi/apps/sense/enums.py b/src/hi/apps/sense/enums.pynew file mode 100644index 00000000..8ef9fa2b--- /dev/null+++ b/src/hi/apps/sense/enums.py@@ -0,0 +1,43 @@+from hi.apps.common.enums import LabeledEnum+++class SensorType(LabeledEnum):++ DISCRETE_VALUE = ( 'Discrete Value', '' ) # Generic for devices+ CONTINUOUS_VALUE = ( 'Continuous Value', '' ) # Generic for device controls+ BLOB = ( 'Blob', '' ) # For custom or large chunks of text+++ # ??? !!! Are the below not needed as just specilizations for each device type?+++ 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+ TEMPERATURE = ( 'Thermometer', '' )+ HUMIDITY = ( 'Humidity', '' )+ AIR_PRESSURE = ( 'Air Pressure', '' )+ LIGHT_LEVEL = ( 'Light Level', '' )+ PRESENCE = ( 'Presence', '' )+ NOISE_LEVEL = ( 'Noise Level', '' )+++class SensedAreaType(LabeledEnum):++ VISIBLE = ( 'Visible', '' )+ MOTION = ( 'Motion', '' )+ PRESENCE = ( 'Presence', '' )+ TEMPERATURE = ( 'Temperature', '' )+ HUMIDITY = ( 'Humidity', '' )+ AIR_PRESSURE = ( 'Air Pressure', '' )++ @property+ def svg_path_style(self):+ raise NotImplementedError()+diff --git a/src/hi/apps/sensor/migrations/__init__.py b/src/hi/apps/sense/migrations/__init__.pysimilarity index 100%rename from src/hi/apps/sensor/migrations/__init__.pyrename to src/hi/apps/sense/migrations/__init__.pydiff --git a/src/hi/apps/sensor/models.py b/src/hi/apps/sense/models.pysimilarity index 69%rename from src/hi/apps/sensor/models.pyrename to src/hi/apps/sense/models.pyindex 4f99607f..dc25af9e 100644--- a/src/hi/apps/sensor/models.py+++ b/src/hi/apps/sense/models.py@@ -6,7 +6,16 @@ from .enums import SensorType, SensedAreaTypeclass Sensor( models.Model ):-+ """+ - Represents an observed state of an entity.+ - An entity 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).+ """+name = models.CharField('Name',max_length = 64,@@ -41,14 +50,14 @@ class Sensor( models.Model ):class SensedEntity(models.Model):sensor = models.ForeignKey(- Entity,+ Sensor,related_name = 'sensed_entities',verbose_name = 'Sensor',on_delete=models.CASCADE,)sensed_entity = models.ForeignKey(Entity,- related_name = 'sensing_source',+ related_name = 'sense_sources',verbose_name = 'Sensed Entity',on_delete=models.CASCADE,)@@ -63,6 +72,11 @@ class SensedArea(models.Model):will come from the SensedAreaType."""+++ # ???? !!! Not needed if an entity can be an Area?++sensor = models.ForeignKey(Entity,related_name = 'sensed_areas',@@ -91,3 +105,22 @@ class SensedArea(models.Model):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(+ Sensor,+ related_name = 'history',+ verbose_name = 'Sensor',+ on_delete=models.CASCADE,+ )+ value = models.CharField(+ 'Value',+ max_length = 255+ )+ created_datetime = models.DateTimeField(+ 'Created',+ auto_now_add = True,+ )+diff --git a/src/hi/apps/sensor/enums.py b/src/hi/apps/sensor/enums.pydeleted file mode 100644index 4bf0fc97..00000000--- a/src/hi/apps/sensor/enums.py+++ /dev/null@@ -1,17 +0,0 @@-from hi.apps.common.enums import LabeledEnum---class SensorType(LabeledEnum):-- CONTINUOUS = ( 'Continuous', '' )- DISCRETE = ( 'Dicrete', '' )---class SensedAreaType(LabeledEnum):-- VISIBLE = ( 'Visible', '' )- MOTION = ( 'Motion', '' )- PRESENCE = ( 'Presence', '' )- TEMPERATURE = ( 'Temperature', '' )- HUMIDITY = ( 'Humidity', '' )- AIR_PRESSURE = ( 'Air Pressure', '' )diff --git a/src/hi/settings/base.py b/src/hi/settings/base.pyindex 87ea6c0c..d0c14138 100644--- a/src/hi/settings/base.py+++ b/src/hi/settings/base.py@@ -139,7 +139,7 @@ INSTALLED_APPS = ['hi.apps.location','hi.apps.entity','hi.apps.collection',- 'hi.apps.sensor',+ 'hi.apps.sense','hi.apps.control',]