Skip to content

Home Information - Your home, your data, organized.

Python

Added new Zone entity and support for closed path defaults.

Anthony Cassandra1b9f7fc28cf8
diff --git a/src/hi/apps/entity/enums.py b/src/hi/apps/entity/enums.py
index f855f4e2..727c36ca 100644
--- a/src/hi/apps/entity/enums.py
+++ b/src/hi/apps/entity/enums.py
@@ -10,11 +10,13 @@ class EntityType(LabeledEnum):
- SVG filename is by convention:
"""
def __init__( self,
- label : str,
- description : str,
- is_path : bool = False ):
+ label : str,
+ description : str,
+ is_path : bool = False,
+ is_path_closed : bool = False ):
super().__init__( label, description )
self.is_path = is_path
+ self.is_path_closed = is_path_closed
return
AIR_CONDITIONER = ( 'Air Conditioner', '' ) # Controls area
@@ -69,7 +71,9 @@ class EntityType(LabeledEnum):
WATER_METER = ( 'Water Meter', '' )
WATER_SHUTOFF_VALVE = ( 'Water Shutoff Valve', '' )
WEATHER_STATION = ( 'Weather Station', '' )
-
+ WINDOW = ( 'Window', '' )
+ ZONE = ( 'Zone', '', True, True )
+
@classmethod
def default(cls):
return cls.OTHER
@@ -115,6 +119,14 @@ class EntityType(LabeledEnum):
class EntityStateType(LabeledEnum):
+ def __init__( self,
+ label : str,
+ description : str,
+ use_default_zone : bool = False ):
+ super().__init__( label, description )
+ self.use_default_zone = use_default_zone
+ return
+
# General types
DISCRETE = ( 'Discrete' , 'Single value, fixed set of possible values' )
CONTINUOUS = ( 'Continuous' , 'For single value with a float type value' )
@@ -130,20 +142,19 @@ class EntityStateType(LabeledEnum):
AIR_PRESSURE = ( 'Air Pressure' , '' )
BANDWIDTH_USAGE = ( 'Bandwidth Usage' , '' )
CONNECTIVITY = ( 'Connectivity' , '' )
+ DATETIME = ( 'Date/Time' , '' )
ELECTRIC_USAGE = ( 'Electric Usage' , '' )
+ HIGH_LOW = ( 'High/Low' , '' )
HUMIDITY = ( 'Humidity' , '' )
- VIDEO_STREAM = ( 'Video Stream' , '' )
- LIGHT_LEVEL = ( 'Light Level' , '' )
+ LIGHT_LEVEL = ( 'Light Level' , '', True )
MOISTURE = ( 'Moisture' , '' )
- MOVEMENT = ( 'Movement' , '' )
- NOISE_LEVEL = ( 'Noise Level' , '' )
+ MOVEMENT = ( 'Movement' , '', True )
ON_OFF = ( 'On/Off' , '' )
- HIGH_LOW = ( 'High/Low' , '' )
OPEN_CLOSE = ( 'Open/Close' , '' )
- PRESENCE = ( 'Presence' , '' )
- SOUND_LEVEL = ( 'Sound Level' , '' )
- DATETIME = ( 'Date/Time' , '' )
- TEMPERATURE = ( 'Temperature' , '' )
+ PRESENCE = ( 'Presence' , '', True )
+ SOUND_LEVEL = ( 'Sound Level' , '', True )
+ TEMPERATURE = ( 'Temperature' , '', True )
+ VIDEO_STREAM = ( 'Video Stream' , '', True )
WATER_FLOW = ( 'Water Flow' , '' )
WIND_SPEED = ( 'Wind Speed' , '' )
diff --git a/src/hi/apps/location/edit/helpers.py b/src/hi/apps/location/edit/helpers.py
index bff41ebc..43018ef6 100644
--- a/src/hi/apps/location/edit/helpers.py
+++ b/src/hi/apps/location/edit/helpers.py
@@ -28,6 +28,8 @@ from .transient_models import (
class LocationEditHelpers:
+ PATH_EDIT_NEW_PATH_RADIUS_PERCENT = 5.0 # Preferrable if this matches Javascript new path sizing.
+
@classmethod
def create_location_view( cls,
request : HttpRequest,
@@ -192,17 +194,28 @@ class LocationEditHelpers:
except EntityPath.DoesNotExist:
pass
- # Default display a line in middle of current view with length 10% of viewbox width
- length = location_view.svg_view_box.width / 10.0
+ # Default display a line in middle of current view with radius 10% of viewbox width
center_x = location_view.svg_view_box.x + ( location_view.svg_view_box.width / 2.0 )
center_y = location_view.svg_view_box.y + ( location_view.svg_view_box.height / 2.0 )
- start_x = center_x - ( length / 2.0 )
- start_y = center_y
- end_x = start_x + length
- end_y = start_y
-
- svg_path = f'M {start_x},{start_y} L {end_x},{end_y}'
+ radius = location_view.svg_view_box.width * ( cls.PATH_EDIT_NEW_PATH_RADIUS_PERCENT / 100.0 )
+ if entity.entity_type.is_path_closed:
+ top_left_x = center_x - radius
+ top_left_y = center_y - radius
+ top_right_x = center_x + radius
+ top_right_y = center_y - radius
+ bottom_right_x = center_x + radius
+ bottom_right_y = center_y + radius
+ bottom_left_x = center_x - radius
+ bottom_left_y = center_y + radius
+ svg_path = f'M {top_left_x},{top_left_y} L {top_right_x},{top_right_y} L {bottom_right_x},{bottom_right_y} L {bottom_left_x},{bottom_left_y} Z'
+ else:
+ start_x = center_x - radius
+ start_y = center_y
+ end_x = start_x + radius
+ end_y = start_y
+ svg_path = f'M {start_x},{start_y} L {end_x},{end_y}'
+
entity_path = EntityPath.objects.create(
entity = entity,
location = location_view.location,
diff --git a/src/hi/hi_grid_view.py b/src/hi/hi_grid_view.py
index f3a2dd7f..4cd02c07 100644
--- a/src/hi/hi_grid_view.py
+++ b/src/hi/hi_grid_view.py
@@ -66,8 +66,7 @@ class HiGridView(View):
})
# This list of views is needed for top buttons
- if ( request.view_parameters.location_view
- and 'location_view_list' not in context ):
+ if ( 'location_view_list' not in context ):
location = request.view_parameters.location_view.location
location_view_list = list( location.views.order_by( 'order_id' ))
context['location_view_list'] = location_view_list
diff --git a/src/hi/static/js/edit-svg-path.js b/src/hi/static/js/edit-svg-path.js
index 761bf795..1c9d581d 100644
--- a/src/hi/static/js/edit-svg-path.js
+++ b/src/hi/static/js/edit-svg-path.js
@@ -63,10 +63,13 @@
65, // 'a'
61 // '+'
];
+ const PATH_ACTION_END_KEY_CODES = [
+ 27 // Escape
+ ];
const PATH_EDIT_PROXY_POINT_RADIUS_PIXELS = 12;
const PATH_EDIT_PROXY_LINE_WIDTH_PIXELS = 5;
- const PATH_EDIT_NEW_PATH_RADIUS_PERCENT = 5; // Better if it matches server default path sizing.
+ const PATH_EDIT_NEW_PATH_RADIUS_PERCENT = 5; // Preferrable if this matches server new path sizing.
const PATH_EDIT_PROXY_LINE_COLOR = 'red';
const PATH_EDIT_PROXY_POINT_COLOR = 'red';
@@ -79,6 +82,7 @@
let gSelectedPathSvgGroup = null;
let gSvgPathEditData = null;
+ let gIgnoreCLick = false; // Set by mouseup handling when non-click actions are needed
$(document).ready(function() {
@@ -97,6 +101,13 @@
Hi.displayEventInfo( 'Path Edit Click', event );
Hi.displayElementInfo( 'Event Target', $(event.target) );
}
+ if ( gSelectedPathSvgGroup && gIgnoreCLick ) {
+ if ( Hi.DEBUG ) { console.log( 'Ignoring click', event ); }
+ gIgnoreCLick = false;
+ event.preventDefault();
+ return;
+ }
+ gIgnoreCLick = false;
const enclosingSvgGroup = $(event.target).closest('g');
if ( enclosingSvgGroup.length > 0 ) {
@@ -132,6 +143,10 @@
if ( PATH_ACTION_ADD_KEY_CODES.includes( event.keyCode ) ) {
addProxyPath();
+
+ } else if ( PATH_ACTION_END_KEY_CODES.includes( event.keyCode ) ) {
+ clearSelectedPathSvgGroup();
+
} else {
if ( ! gSvgPathEditData.selectedProxyElement ) {
return;
@@ -631,14 +646,14 @@
x: svgCenter.x + svgUnitRadius.x,
y: svgCenter.y - svgUnitRadius.y,
};
- const bottomLeftSvgPoint = {
- x: svgCenter.x - svgUnitRadius.x,
- y: svgCenter.y + svgUnitRadius.y,
- };
const bottomRightSvgPoint = {
x: svgCenter.x + svgUnitRadius.x,
y: svgCenter.y + svgUnitRadius.y,
};
+ const bottomLeftSvgPoint = {
+ x: svgCenter.x - svgUnitRadius.x,
+ y: svgCenter.y + svgUnitRadius.y,
+ };
let topLeftProxyPoint = createProxyPathProxyPoint( topLeftSvgPoint.x,
topLeftSvgPoint.y );
@@ -764,6 +779,7 @@
event.preventDefault();
saveSvgPath();
gSvgPathEditData.dragProxyPoint = null;
+ gIgnoreCLick = true;
$(document).off('mousemove', onMouseMove);
$(document).off('mouseup', onMouseUp);
}