simo 2.0.5__py3-none-any.whl → 2.0.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of simo might be problematic. Click here for more details.

Files changed (165) hide show
  1. simo/__pycache__/settings.cpython-38.pyc +0 -0
  2. simo/__pycache__/urls.cpython-38.pyc +0 -0
  3. simo/core/__pycache__/admin.cpython-38.pyc +0 -0
  4. simo/core/__pycache__/api.cpython-38.pyc +0 -0
  5. simo/core/__pycache__/api_auth.cpython-38.pyc +0 -0
  6. simo/core/__pycache__/api_meta.cpython-38.pyc +0 -0
  7. simo/core/__pycache__/auto_urls.cpython-38.pyc +0 -0
  8. simo/core/__pycache__/autocomplete_views.cpython-38.pyc +0 -0
  9. simo/core/__pycache__/base_types.cpython-38.pyc +0 -0
  10. simo/core/__pycache__/context.cpython-38.pyc +0 -0
  11. simo/core/__pycache__/controllers.cpython-38.pyc +0 -0
  12. simo/core/__pycache__/events.cpython-38.pyc +0 -0
  13. simo/core/__pycache__/forms.cpython-38.pyc +0 -0
  14. simo/core/__pycache__/gateways.cpython-38.pyc +0 -0
  15. simo/core/__pycache__/managers.cpython-38.pyc +0 -0
  16. simo/core/__pycache__/middleware.cpython-38.pyc +0 -0
  17. simo/core/__pycache__/models.cpython-38.pyc +0 -0
  18. simo/core/__pycache__/permissions.cpython-38.pyc +0 -0
  19. simo/core/__pycache__/serializers.cpython-38.pyc +0 -0
  20. simo/core/__pycache__/socket_consumers.cpython-38.pyc +0 -0
  21. simo/core/__pycache__/tasks.cpython-38.pyc +0 -0
  22. simo/core/__pycache__/views.cpython-38.pyc +0 -0
  23. simo/core/admin.py +8 -10
  24. simo/core/api.py +2 -3
  25. simo/core/db_backend/__pycache__/__init__.cpython-38.pyc +0 -0
  26. simo/core/db_backend/__pycache__/base.cpython-38.pyc +0 -0
  27. simo/core/drf_braces/__pycache__/__init__.cpython-38.pyc +0 -0
  28. simo/core/drf_braces/__pycache__/utils.cpython-38.pyc +0 -0
  29. simo/core/drf_braces/fields/__pycache__/__init__.cpython-38.pyc +0 -0
  30. simo/core/drf_braces/fields/__pycache__/_fields.cpython-38.pyc +0 -0
  31. simo/core/drf_braces/fields/__pycache__/custom.cpython-38.pyc +0 -0
  32. simo/core/drf_braces/fields/__pycache__/mixins.cpython-38.pyc +0 -0
  33. simo/core/drf_braces/fields/__pycache__/modified.cpython-38.pyc +0 -0
  34. simo/core/drf_braces/serializers/__pycache__/__init__.cpython-38.pyc +0 -0
  35. simo/core/drf_braces/serializers/__pycache__/form_serializer.cpython-38.pyc +0 -0
  36. simo/core/forms.py +8 -6
  37. simo/core/migrations/__pycache__/0001_initial.cpython-38.pyc +0 -0
  38. simo/core/migrations/__pycache__/0002_load_icons.cpython-38.pyc +0 -0
  39. simo/core/migrations/__pycache__/0003_create_default_zones_and_categories.cpython-38.pyc +0 -0
  40. simo/core/migrations/__pycache__/0004_create_generic.cpython-38.pyc +0 -0
  41. simo/core/migrations/__pycache__/0005_component_subcomponents.cpython-38.pyc +0 -0
  42. simo/core/migrations/__pycache__/0006_alter_component_subcomponents.cpython-38.pyc +0 -0
  43. simo/core/migrations/__pycache__/0007_component_change_init_to.cpython-38.pyc +0 -0
  44. simo/core/migrations/__pycache__/0008_alter_component_change_init_to.cpython-38.pyc +0 -0
  45. simo/core/migrations/__pycache__/0009_auto_20220707_1404.cpython-38.pyc +0 -0
  46. simo/core/migrations/__pycache__/0010_historyaggregate.cpython-38.pyc +0 -0
  47. simo/core/migrations/__pycache__/0011_component_last_change.cpython-38.pyc +0 -0
  48. simo/core/migrations/__pycache__/0012_instance.cpython-38.pyc +0 -0
  49. simo/core/migrations/__pycache__/0013_auto_20231003_0754.cpython-38.pyc +0 -0
  50. simo/core/migrations/__pycache__/0014_zone_instance.cpython-38.pyc +0 -0
  51. simo/core/migrations/__pycache__/0015_auto_20231004_1113.cpython-38.pyc +0 -0
  52. simo/core/migrations/__pycache__/0016_auto_20231004_1113.cpython-38.pyc +0 -0
  53. simo/core/migrations/__pycache__/0017_auto_20231004_1313.cpython-38.pyc +0 -0
  54. simo/core/migrations/__pycache__/0018_auto_20231005_0622.cpython-38.pyc +0 -0
  55. simo/core/migrations/__pycache__/0019_alter_gateway_type.cpython-38.pyc +0 -0
  56. simo/core/migrations/__pycache__/0020_component_meta.cpython-38.pyc +0 -0
  57. simo/core/migrations/__pycache__/0021_auto_20231020_1041.cpython-38.pyc +0 -0
  58. simo/core/migrations/__pycache__/0026_category_instance.cpython-38.pyc +0 -0
  59. simo/core/migrations/__pycache__/0027_remove_component_tags.cpython-38.pyc +0 -0
  60. simo/core/migrations/__pycache__/0028_rename_subcomponents_component_slaves.cpython-38.pyc +0 -0
  61. simo/core/migrations/__pycache__/0029_auto_20240229_1331.cpython-38.pyc +0 -0
  62. simo/core/migrations/__pycache__/__init__.cpython-38.pyc +0 -0
  63. simo/core/models.py +30 -46
  64. simo/core/serializers.py +2 -3
  65. simo/core/templatetags/__pycache__/__init__.cpython-38.pyc +0 -0
  66. simo/core/templatetags/__pycache__/components_list.cpython-38.pyc +0 -0
  67. simo/core/utils/__pycache__/__init__.cpython-38.pyc +0 -0
  68. simo/core/utils/__pycache__/admin.cpython-38.pyc +0 -0
  69. simo/core/utils/__pycache__/config_values.cpython-38.pyc +0 -0
  70. simo/core/utils/__pycache__/easing.cpython-38.pyc +0 -0
  71. simo/core/utils/__pycache__/form_fields.cpython-38.pyc +0 -0
  72. simo/core/utils/__pycache__/form_widgets.cpython-38.pyc +0 -0
  73. simo/core/utils/__pycache__/formsets.cpython-38.pyc +0 -0
  74. simo/core/utils/__pycache__/helpers.cpython-38.pyc +0 -0
  75. simo/core/utils/__pycache__/logs.cpython-38.pyc +0 -0
  76. simo/core/utils/__pycache__/mixins.cpython-38.pyc +0 -0
  77. simo/core/utils/__pycache__/model_helpers.cpython-38.pyc +0 -0
  78. simo/core/utils/__pycache__/relay.cpython-38.pyc +0 -0
  79. simo/core/utils/__pycache__/serialization.cpython-38.pyc +0 -0
  80. simo/core/utils/__pycache__/type_constants.cpython-38.pyc +0 -0
  81. simo/core/utils/__pycache__/validators.cpython-38.pyc +0 -0
  82. simo/core/utils/type_constants.py +32 -11
  83. simo/fleet/__pycache__/admin.cpython-38.pyc +0 -0
  84. simo/fleet/__pycache__/api.cpython-38.pyc +0 -0
  85. simo/fleet/__pycache__/auto_urls.cpython-38.pyc +0 -0
  86. simo/fleet/__pycache__/controllers.cpython-38.pyc +0 -0
  87. simo/fleet/__pycache__/forms.cpython-38.pyc +0 -0
  88. simo/fleet/__pycache__/gateways.cpython-38.pyc +0 -0
  89. simo/fleet/__pycache__/managers.cpython-38.pyc +0 -0
  90. simo/fleet/__pycache__/models.cpython-38.pyc +0 -0
  91. simo/fleet/__pycache__/serializers.cpython-38.pyc +0 -0
  92. simo/fleet/__pycache__/socket_consumers.cpython-38.pyc +0 -0
  93. simo/fleet/__pycache__/utils.cpython-38.pyc +0 -0
  94. simo/fleet/__pycache__/views.cpython-38.pyc +0 -0
  95. simo/fleet/migrations/__pycache__/0025_auto_20240130_1334.cpython-38.pyc +0 -0
  96. simo/fleet/migrations/__pycache__/0026_rename_i2cinterface_scl_pin_and_more.cpython-38.pyc +0 -0
  97. simo/fleet/migrations/__pycache__/0027_auto_20240306_0802.cpython-38.pyc +0 -0
  98. simo/fleet/migrations/__pycache__/0028_remove_i2cinterface_scl_pin_no_and_more.cpython-38.pyc +0 -0
  99. simo/fleet/migrations/__pycache__/0029_alter_i2cinterface_scl_pin_and_more.cpython-38.pyc +0 -0
  100. simo/fleet/migrations/__pycache__/0030_colonelpin_label_alter_colonel_type.cpython-38.pyc +0 -0
  101. simo/fleet/migrations/__pycache__/0031_alter_colonel_type.cpython-38.pyc +0 -0
  102. simo/generic/__pycache__/__init__.cpython-38.pyc +0 -0
  103. simo/generic/__pycache__/app_widgets.cpython-38.pyc +0 -0
  104. simo/generic/__pycache__/base_types.cpython-38.pyc +0 -0
  105. simo/generic/__pycache__/controllers.cpython-38.pyc +0 -0
  106. simo/generic/__pycache__/forms.cpython-38.pyc +0 -0
  107. simo/generic/__pycache__/gateways.cpython-38.pyc +0 -0
  108. simo/generic/__pycache__/models.cpython-38.pyc +0 -0
  109. simo/generic/__pycache__/routing.cpython-38.pyc +0 -0
  110. simo/generic/__pycache__/socket_consumers.cpython-38.pyc +0 -0
  111. simo/generic/controllers.py +0 -7
  112. simo/generic/forms.py +0 -3
  113. simo/generic/gateways.py +0 -8
  114. simo/multimedia/__pycache__/__init__.cpython-38.pyc +0 -0
  115. simo/multimedia/__pycache__/admin.cpython-38.pyc +0 -0
  116. simo/multimedia/__pycache__/api.cpython-38.pyc +0 -0
  117. simo/multimedia/__pycache__/app_widgets.cpython-38.pyc +0 -0
  118. simo/multimedia/__pycache__/base_types.cpython-38.pyc +0 -0
  119. simo/multimedia/__pycache__/controllers.cpython-38.pyc +0 -0
  120. simo/multimedia/__pycache__/forms.cpython-38.pyc +0 -0
  121. simo/multimedia/__pycache__/models.cpython-38.pyc +0 -0
  122. simo/multimedia/__pycache__/serializers.cpython-38.pyc +0 -0
  123. simo/multimedia/migrations/__pycache__/0001_initial.cpython-38.pyc +0 -0
  124. simo/multimedia/migrations/__pycache__/0002_sound_length.cpython-38.pyc +0 -0
  125. simo/multimedia/migrations/__pycache__/0003_alter_sound_length.cpython-38.pyc +0 -0
  126. simo/multimedia/migrations/__pycache__/0004_auto_20231023_1055.cpython-38.pyc +0 -0
  127. simo/multimedia/migrations/__pycache__/__init__.cpython-38.pyc +0 -0
  128. simo/notifications/__pycache__/__init__.cpython-38.pyc +0 -0
  129. simo/notifications/__pycache__/admin.cpython-38.pyc +0 -0
  130. simo/notifications/__pycache__/api.cpython-38.pyc +0 -0
  131. simo/notifications/__pycache__/models.cpython-38.pyc +0 -0
  132. simo/notifications/__pycache__/serializers.cpython-38.pyc +0 -0
  133. simo/notifications/migrations/__pycache__/0001_initial.cpython-38.pyc +0 -0
  134. simo/notifications/migrations/__pycache__/0002_notification_instance.cpython-38.pyc +0 -0
  135. simo/notifications/migrations/__pycache__/__init__.cpython-38.pyc +0 -0
  136. simo/users/__pycache__/admin.cpython-38.pyc +0 -0
  137. simo/users/__pycache__/api.cpython-38.pyc +0 -0
  138. simo/users/__pycache__/auto_urls.cpython-38.pyc +0 -0
  139. simo/users/__pycache__/middleware.cpython-38.pyc +0 -0
  140. simo/users/__pycache__/models.cpython-38.pyc +0 -0
  141. simo/users/__pycache__/serializers.cpython-38.pyc +0 -0
  142. simo/users/__pycache__/sso_urls.cpython-38.pyc +0 -0
  143. simo/users/migrations/__pycache__/0001_initial.cpython-38.pyc +0 -0
  144. simo/users/migrations/__pycache__/0002_componentpermission.cpython-38.pyc +0 -0
  145. simo/users/migrations/__pycache__/0003_create_roles_and_system_user.cpython-38.pyc +0 -0
  146. simo/users/migrations/__pycache__/0004_user_secret_key.cpython-38.pyc +0 -0
  147. simo/users/migrations/__pycache__/0005_permissionsrole_instance.cpython-38.pyc +0 -0
  148. simo/users/migrations/__pycache__/0006_auto_20231003_0850.cpython-38.pyc +0 -0
  149. simo/users/migrations/__pycache__/0007_auto_20231003_1228.cpython-38.pyc +0 -0
  150. simo/users/migrations/__pycache__/0008_auto_20231003_1229.cpython-38.pyc +0 -0
  151. simo/users/migrations/__pycache__/0009_remove_user_role.cpython-38.pyc +0 -0
  152. simo/users/migrations/__pycache__/0010_auto_20231004_1313.cpython-38.pyc +0 -0
  153. simo/users/migrations/__pycache__/0011_auto_20231004_1313.cpython-38.pyc +0 -0
  154. simo/users/migrations/__pycache__/0012_alter_userinstancerole_unique_together.cpython-38.pyc +0 -0
  155. simo/users/migrations/__pycache__/0013_remove_user_roles.cpython-38.pyc +0 -0
  156. simo/users/migrations/__pycache__/0014_user_roles.cpython-38.pyc +0 -0
  157. simo/users/migrations/__pycache__/0015_remove_user_at_home.cpython-38.pyc +0 -0
  158. simo/users/migrations/__pycache__/0016_auto_20231005_1050.cpython-38.pyc +0 -0
  159. simo/users/migrations/__pycache__/0025_rename_name_fingerprint_type_and_more.cpython-38.pyc +0 -0
  160. simo/users/migrations/__pycache__/__init__.cpython-38.pyc +0 -0
  161. {simo-2.0.5.dist-info → simo-2.0.6.dist-info}/METADATA +1 -1
  162. {simo-2.0.5.dist-info → simo-2.0.6.dist-info}/RECORD +165 -77
  163. {simo-2.0.5.dist-info → simo-2.0.6.dist-info}/LICENSE.md +0 -0
  164. {simo-2.0.5.dist-info → simo-2.0.6.dist-info}/WHEEL +0 -0
  165. {simo-2.0.5.dist-info → simo-2.0.6.dist-info}/top_level.txt +0 -0
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
simo/core/admin.py CHANGED
@@ -9,8 +9,7 @@ from django.views.decorators.csrf import csrf_protect
9
9
  from django.shortcuts import redirect, render
10
10
  from simo.users.models import ComponentPermission
11
11
  from .utils.type_constants import (
12
- ALL_BASE_TYPES,
13
- get_all_gateways, get_controller_types_map
12
+ ALL_BASE_TYPES, GATEWAYS_MAP, CONTROLLERS_BY_GATEWAY
14
13
  )
15
14
  from .models import Instance, Icon, Gateway, Component, Zone, Category
16
15
  from .forms import (
@@ -22,7 +21,6 @@ from .forms import (
22
21
  )
23
22
  from .filters import ZonesFilter
24
23
  from .widgets import AdminImageWidget
25
- from .middleware import get_current_instance
26
24
  from simo.conf import dynamic_settings
27
25
 
28
26
  csrf_protect_m = method_decorator(csrf_protect)
@@ -156,7 +154,7 @@ class GatewayAdmin(admin.ModelAdmin):
156
154
  }
157
155
  if request.session.get('gateway_type'):
158
156
  try:
159
- formClass = get_all_gateways().get(
157
+ formClass = GATEWAYS_MAP.get(
160
158
  request.session.get('gateway_type')
161
159
  ).config_form
162
160
  except:
@@ -188,7 +186,7 @@ class GatewayAdmin(admin.ModelAdmin):
188
186
  )
189
187
  except:
190
188
  ctx['error'] = '%s gateway already exists!' \
191
- % get_all_gateways().get(
189
+ % GATEWAYS_MAP.get(
192
190
  request.session.get('gateway_type'), 'None'
193
191
  ).name
194
192
  else:
@@ -210,7 +208,7 @@ class GatewayAdmin(admin.ModelAdmin):
210
208
 
211
209
  def get_form(self, request, obj=None, change=False, **kwargs):
212
210
  if obj:
213
- gateway_class = get_all_gateways().get(obj.type)
211
+ gateway_class = GATEWAYS_MAP.get(obj.type)
214
212
  if gateway_class:
215
213
  return gateway_class.config_form
216
214
  return BaseGatewayForm
@@ -323,8 +321,8 @@ class ComponentAdmin(admin.ModelAdmin):
323
321
 
324
322
  if request.session.get('add_comp_type'):
325
323
  try:
326
- controller_cls = get_controller_types_map(
327
- gateway
324
+ controller_cls = CONTROLLERS_BY_GATEWAY.get(
325
+ gateway, {}
328
326
  )[request.session['add_comp_type']]
329
327
  except:
330
328
  request.session.pop('add_comp_type')
@@ -430,8 +428,8 @@ class ComponentAdmin(admin.ModelAdmin):
430
428
  def get_form(self, request, obj=None, change=False, **kwargs):
431
429
  if obj:
432
430
  try:
433
- self.form = get_controller_types_map(
434
- obj.gateway
431
+ self.form = CONTROLLERS_BY_GATEWAY.get(
432
+ obj.gateway, {}
435
433
  )[obj.controller_uid].config_form
436
434
  except KeyError:
437
435
  pass
simo/core/api.py CHANGED
@@ -182,7 +182,6 @@ class ComponentViewSet(InstanceMixin, viewsets.ModelViewSet):
182
182
  return singular
183
183
 
184
184
  def perform_controller_method(self, json_data, component):
185
- component.prepare_controller()
186
185
  for method_name, param in json_data.items():
187
186
  if not hasattr(component, method_name):
188
187
  raise APIValidationError(
@@ -584,10 +583,10 @@ class ControllerTypes(InstanceMixin, viewsets.GenericViewSet):
584
583
  return permissions
585
584
 
586
585
  def list(self, request, *args, **kwargs):
587
- from .utils.type_constants import get_controller_types_map
586
+ from .utils.type_constants import CONTROLLER_TYPES_MAP
588
587
  data = {}
589
588
 
590
- for uid, cls in get_controller_types_map().items():
589
+ for uid, cls in CONTROLLER_TYPES_MAP.items():
591
590
  if cls.gateway_class.name not in data:
592
591
  data[cls.gateway_class.name] = []
593
592
  data[cls.gateway_class.name].append({
simo/core/forms.py CHANGED
@@ -260,10 +260,12 @@ class CompTypeSelectForm(forms.Form):
260
260
  def __init__(self, gateway, *args, **kwargs):
261
261
  super().__init__(*args, **kwargs)
262
262
  if gateway:
263
- from .utils.type_constants import get_controller_types_choices
264
- self.fields['controller_type'].choices = get_controller_types_choices(
265
- gateway
266
- )
263
+ from .utils.type_constants import CONTROLLERS_BY_GATEWAY
264
+ self.fields['controller_type'].choices = [
265
+ (cls.uid, cls.name) for cls in CONTROLLERS_BY_GATEWAY.get(
266
+ gateway.handler.uid, {}
267
+ ).values()
268
+ ]
267
269
 
268
270
 
269
271
  class ComponentAdminForm(forms.ModelForm):
@@ -300,8 +302,8 @@ class ComponentAdminForm(forms.ModelForm):
300
302
  self.gateway = self.instance.gateway
301
303
  self.controller = self.instance.controller
302
304
  else:
303
- from .utils.type_constants import get_controller_types_map
304
- ControllerClass = get_controller_types_map().get(self.controller_uid)
305
+ from .utils.type_constants import CONTROLLER_TYPES_MAP
306
+ ControllerClass = CONTROLLER_TYPES_MAP.get(self.controller_uid)
305
307
  if ControllerClass:
306
308
  self.controller = ControllerClass(self.instance)
307
309
  self.gateway = Gateway.objects.filter(
simo/core/models.py CHANGED
@@ -217,16 +217,11 @@ class Gateway(DirtyFieldsMixin, models.Model, SimoAdminMixin):
217
217
  return self.type
218
218
 
219
219
  def __init__(self, *args, **kwargs):
220
- from .utils.type_constants import get_all_gateways
221
- ALL_GATEWAYS = get_all_gateways()
222
- GATEWAYS_CHOICES = [
223
- (slug, cls.name) for slug, cls in ALL_GATEWAYS.items()
224
- ]
225
- GATEWAYS_CHOICES.sort(key=lambda e: e[1])
220
+ from .utils.type_constants import GATEWAYS_MAP, GATEWAYS_CHOICES
226
221
  self._meta.get_field('type').choices = GATEWAYS_CHOICES
227
222
  super().__init__(*args, **kwargs)
228
223
 
229
- gateway_class = ALL_GATEWAYS.get(self.type)
224
+ gateway_class = GATEWAYS_MAP.get(self.type)
230
225
  if gateway_class:
231
226
  self.handler = gateway_class(self)
232
227
  if hasattr(self.handler, 'run'):
@@ -272,8 +267,8 @@ class Gateway(DirtyFieldsMixin, models.Model, SimoAdminMixin):
272
267
 
273
268
  def process_discovery(self, data):
274
269
  self.refresh_from_db()
275
- from .utils.type_constants import get_controller_types_map
276
- ControllerClass = get_controller_types_map().get(
270
+ from .utils.type_constants import CONTROLLER_TYPES_MAP
271
+ ControllerClass = CONTROLLER_TYPES_MAP.get(
277
272
  self.discovery['controller_uid']
278
273
  )
279
274
  if ControllerClass and hasattr(
@@ -403,18 +398,7 @@ def is_in_alarm(self):
403
398
 
404
399
  def __init__(self, *args, **kwargs):
405
400
  super().__init__(*args, **kwargs)
406
- # Goes in zero seconds!
407
- if self.instance_methods:
408
- custom_methods = {}
409
- funcType = type(self.save)
410
- try:
411
- exec(self.instance_methods, None, custom_methods)
412
- except:
413
- pass
414
- for key, val in custom_methods.items():
415
- if not callable(val):
416
- continue
417
- setattr(self, key, funcType(val, self))
401
+ self.prepare_controller()
418
402
 
419
403
  def __str__(self):
420
404
  if self.zone:
@@ -424,40 +408,40 @@ def is_in_alarm(self):
424
408
  @cached_property
425
409
  def controller(self):
426
410
  from .utils.type_constants import (
427
- get_controller_types_map,
428
- get_controller_types_choices
411
+ CONTROLLERS_BY_GATEWAY,
412
+ CONTROLLER_TYPES_CHOICES
429
413
  )
430
- self._meta.get_field('controller_uid').choices = \
431
- get_controller_types_choices()
414
+ self._meta.get_field('controller_uid').choices = CONTROLLER_TYPES_CHOICES
432
415
  if self.controller_uid:
433
416
  controller_cls = None
434
- if self.id and not 'test' in sys.argv:
435
- try:
436
- controller_cls = cache.get('c_%d_contr_cls' % self.id)
437
- except:
438
- pass
439
417
  if not controller_cls:
440
- controller_cls = get_controller_types_map(
441
- self.gateway
418
+ controller_cls = CONTROLLERS_BY_GATEWAY.get(
419
+ self.gateway.type, {}
442
420
  ).get(self.controller_uid)
443
- if controller_cls and self.id and not 'test' in sys.argv:
444
- cache.set(
445
- 'c_%d_contr_cls' % self.id,
446
- controller_cls, None
447
- )
448
421
  if controller_cls:
449
422
  return controller_cls(self)
450
423
 
451
424
  def prepare_controller(self):
452
- if not self.controller:
453
- return
454
- controller_methods = [m for m in inspect.getmembers(
455
- self.controller, predicate=inspect.ismethod
456
- ) if not m[0].startswith('_')]
457
- for method in controller_methods:
458
- setattr(self, method[0], method[1])
459
- if not self.id:
460
- self.value = self.controller.default_value
425
+ if self.controller:
426
+ controller_methods = [m for m in inspect.getmembers(
427
+ self.controller, predicate=inspect.ismethod
428
+ ) if not m[0].startswith('_')]
429
+ for method in controller_methods:
430
+ setattr(self, method[0], method[1])
431
+ if not self.id:
432
+ self.value = self.controller.default_value
433
+
434
+ if self.instance_methods:
435
+ custom_methods = {}
436
+ funcType = type(self.save)
437
+ try:
438
+ exec(self.instance_methods, None, custom_methods)
439
+ except:
440
+ pass
441
+ for key, val in custom_methods.items():
442
+ if not callable(val):
443
+ continue
444
+ setattr(self, key, funcType(val, self))
461
445
 
462
446
  def get_socket_url(self):
463
447
  return reverse_lazy(
simo/core/serializers.py CHANGED
@@ -284,10 +284,9 @@ class ComponentSerializer(FormSerializer):
284
284
  def set_form_cls(self):
285
285
  self.Meta.form = ComponentAdminForm
286
286
  if not isinstance(self.instance, Iterable):
287
- from .utils.type_constants import get_controller_types_map
288
- controllers_map = get_controller_types_map()
287
+ from .utils.type_constants import CONTROLLER_TYPES_MAP
289
288
  if not self.instance:
290
- controller = controllers_map.get(
289
+ controller = CONTROLLER_TYPES_MAP.get(
291
290
  #'simo.generic.controllers.AlarmClock'
292
291
  self.context['request'].META.get('HTTP_CONTROLLER')
293
292
  )
@@ -19,20 +19,32 @@ def get_controller_types_map(gateway=None):
19
19
  except ModuleNotFoundError:
20
20
  continue
21
21
  for cls_name, cls in configs.__dict__.items():
22
- if inspect.isclass(cls) and issubclass(cls, ControllerBase) \
23
- and not inspect.isabstract(cls):
24
- if gateway:
22
+ if not inspect.isclass(cls):
23
+ continue
24
+ if not issubclass(cls, ControllerBase):
25
+ continue
26
+ if inspect.isabstract(cls):
27
+ continue
28
+ if gateway:
29
+ if issubclass(gateway, BaseGatewayHandler) \
30
+ or isinstance(gateway, BaseGatewayHandler):
31
+ if gateway.uid != cls.gateway_class.uid:
32
+ continue
33
+ else:
25
34
  try:
26
- same = gateway.type == cls.gateway_class.uid
35
+ same = gateway.handler.uid == cls.gateway_class.uid
27
36
  except:
28
37
  continue
29
38
  else:
30
39
  if not same:
31
40
  continue
32
- controllers_map[cls.uid] = cls
41
+ controllers_map[cls.uid] = cls
33
42
  return controllers_map
34
43
 
35
44
 
45
+ CONTROLLER_TYPES_MAP = get_controller_types_map()
46
+
47
+
36
48
  def get_controller_types_choices(gateway=None):
37
49
  choices = []
38
50
  for controller_cls in get_controller_types_map(gateway).values():
@@ -40,11 +52,8 @@ def get_controller_types_choices(gateway=None):
40
52
  return choices
41
53
 
42
54
 
43
- #ALL_CONTROLLER_TYPES = get_controller_types_map()
44
- # CONTROLLER_TYPE_CHOICES = [
45
- # (slug, cls.name) for slug, cls in ALL_CONTROLLER_TYPES.items()
46
- # ]
47
- # CONTROLLER_TYPE_CHOICES.sort(key=lambda e: e[0])
55
+ CONTROLLER_TYPES_CHOICES = get_controller_types_choices()
56
+
48
57
 
49
58
  def get_all_gateways():
50
59
  all_gateways = {}
@@ -65,13 +74,25 @@ def get_all_gateways():
65
74
  return all_gateways
66
75
 
67
76
 
77
+ GATEWAYS_MAP = get_all_gateways()
78
+
79
+
68
80
  def get_gateway_choices():
69
81
  choices = [
70
- (slug, cls.name) for slug, cls in get_all_gateways().items()
82
+ (slug, cls.name) for slug, cls in GATEWAYS_MAP.items()
71
83
  ]
72
84
  choices.sort(key=lambda e: e[1])
73
85
  return choices
74
86
 
87
+ GATEWAYS_CHOICES = get_gateway_choices()
88
+
89
+
90
+ CONTROLLERS_BY_GATEWAY = {}
91
+ for gateway_slug, gateway_cls in GATEWAYS_MAP.items():
92
+ CONTROLLERS_BY_GATEWAY[gateway_slug] = {}
93
+ for ctrl_uid, ctrl_cls in get_controller_types_map(gateway_cls).items():
94
+ CONTROLLERS_BY_GATEWAY[gateway_slug][ctrl_uid] = ctrl_cls
95
+
75
96
 
76
97
  ALL_BASE_TYPES = {}
77
98
  for name, app in apps.app_configs.items():
Binary file
Binary file
Binary file
Binary file
Binary file