Skip to content

Home Information - Your home, your data, organized.

Python

Fix Home Assistant device controls and implement service calls (Issue #51) (#53)

Tony C2580a574851f
diff --git a/src/hi/apps/attribute/models.py b/src/hi/apps/attribute/models.py
index 307adee8..8e653da3 100644
--- a/src/hi/apps/attribute/models.py
+++ b/src/hi/apps/attribute/models.py
@@ -7,7 +7,7 @@ from django.db import models
from hi.apps.attribute.value_ranges import PredefinedValueRanges
from hi.apps.common.file_utils import generate_unique_filename
-from hi.integrations.integration_key import IntegrationKey
+from hi.integrations.transient_models import IntegrationKey
from .enums import (
AttributeValueType,
diff --git a/src/hi/apps/attribute/tests/test_models.py b/src/hi/apps/attribute/tests/test_models.py
index 947caae7..e8ba3117 100644
--- a/src/hi/apps/attribute/tests/test_models.py
+++ b/src/hi/apps/attribute/tests/test_models.py
@@ -5,7 +5,7 @@ from django.core.files.uploadedfile import SimpleUploadedFile
from hi.apps.attribute.models import AttributeModel
from hi.apps.attribute.enums import AttributeValueType, AttributeType
-from hi.integrations.integration_key import IntegrationKey
+from hi.integrations.transient_models import IntegrationKey
from hi.tests.base_test_case import BaseTestCase
logging.disable(logging.CRITICAL)
diff --git a/src/hi/apps/control/controller_manager.py b/src/hi/apps/control/controller_manager.py
index 2c433d21..7cca52f2 100644
--- a/src/hi/apps/control/controller_manager.py
+++ b/src/hi/apps/control/controller_manager.py
@@ -35,7 +35,7 @@ class ControllerManager( Singleton ):
integration_controller = integration_gateway.get_controller()
control_result = integration_controller.do_control(
- integration_key = controller.integration_key,
+ integration_details = controller.get_integration_details(),
control_value = control_value,
)
return control_result
diff --git a/src/hi/apps/control/migrations/0002_add_integration_metadata.py b/src/hi/apps/control/migrations/0002_add_integration_metadata.py
new file mode 100644
index 00000000..f64ec82a
--- /dev/null
+++ b/src/hi/apps/control/migrations/0002_add_integration_metadata.py
@@ -0,0 +1,23 @@
+# Generated by Django 4.2.15 on 2025-08-15 05:12
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("control", "0001_initial"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="controller",
+ name="integration_metadata",
+ field=models.JSONField(
+ blank=True,
+ default=dict,
+ help_text="Integration-specific metadata (e.g., HA domain, device capabilities)",
+ verbose_name="Integration Metadata",
+ ),
+ ),
+ ]
diff --git a/src/hi/apps/control/migrations/0003_rename_integration_metadata_controller_integration_payload.py b/src/hi/apps/control/migrations/0003_rename_integration_metadata_controller_integration_payload.py
new file mode 100644
index 00000000..b8df145b
--- /dev/null
+++ b/src/hi/apps/control/migrations/0003_rename_integration_metadata_controller_integration_payload.py
@@ -0,0 +1,18 @@
+# Generated by Django 4.2.15 on 2025-08-15 20:48
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("control", "0002_add_integration_metadata"),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name="controller",
+ old_name="integration_metadata",
+ new_name="integration_payload",
+ ),
+ ]
diff --git a/src/hi/apps/control/migrations/0004_alter_controller_integration_payload.py b/src/hi/apps/control/migrations/0004_alter_controller_integration_payload.py
new file mode 100644
index 00000000..94c99a24
--- /dev/null
+++ b/src/hi/apps/control/migrations/0004_alter_controller_integration_payload.py
@@ -0,0 +1,23 @@
+# Generated by Django 4.2.15 on 2025-08-15 20:48
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("control", "0003_rename_integration_metadata_controller_integration_payload"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="controller",
+ name="integration_payload",
+ field=models.JSONField(
+ blank=True,
+ default=dict,
+ help_text="Integration-specific data (e.g., HA domain, device capabilities)",
+ verbose_name="Integration Payload",
+ ),
+ ),
+ ]
diff --git a/src/hi/apps/control/models.py b/src/hi/apps/control/models.py
index 54fe54d3..37877942 100644
--- a/src/hi/apps/control/models.py
+++ b/src/hi/apps/control/models.py
@@ -1,12 +1,12 @@
from django.db import models
from hi.apps.entity.models import EntityState
-from hi.integrations.models import IntegrationKeyModel
+from hi.integrations.models import IntegrationDetailsModel
from .enums import ControllerType
-class Controller( IntegrationKeyModel ):
+class Controller( IntegrationDetailsModel ):
"""
- Represents an action that can be taken.
- Will control exactly one EntityState
diff --git a/src/hi/apps/control/tests/test_controller_manager.py b/src/hi/apps/control/tests/test_controller_manager.py
index 0f927eda..ae47fea9 100644
--- a/src/hi/apps/control/tests/test_controller_manager.py
+++ b/src/hi/apps/control/tests/test_controller_manager.py
@@ -77,10 +77,11 @@ class TestControllerManager(BaseTestCase):
integration_id='test_id'
)
mock_integration_gateway.get_controller.assert_called_once()
- mock_integration_controller.do_control.assert_called_once_with(
- integration_key=controller.integration_key,
- control_value='on'
- )
+ # Get the actual call arguments
+ call_args = mock_integration_controller.do_control.call_args
+ self.assertEqual(call_args.kwargs['control_value'], 'on')
+ self.assertEqual(call_args.kwargs['integration_details'].key, controller.integration_key)
+ self.assertEqual(call_args.kwargs['integration_details'].payload, controller.integration_payload)
self.assertEqual(result, mock_control_result)
return
@@ -126,10 +127,11 @@ class TestControllerManager(BaseTestCase):
result = asyncio.run(run_async_test())
# Should delegate to sync method through sync_to_async
- mock_integration_controller.do_control.assert_called_once_with(
- integration_key=controller.integration_key,
- control_value='off'
- )
+ # Get the actual call arguments
+ call_args = mock_integration_controller.do_control.call_args
+ self.assertEqual(call_args.kwargs['control_value'], 'off')
+ self.assertEqual(call_args.kwargs['integration_details'].key, controller.integration_key)
+ self.assertEqual(call_args.kwargs['integration_details'].payload, controller.integration_payload)
self.assertEqual(result, mock_control_result)
return
diff --git a/src/hi/apps/entity/enums.py b/src/hi/apps/entity/enums.py
index 020226c4..bdf2128e 100644
--- a/src/hi/apps/entity/enums.py
+++ b/src/hi/apps/entity/enums.py
@@ -123,6 +123,7 @@ class EntityStateType(LabeledEnum):
ELECTRIC_USAGE = ( 'Electric Usage' , '' )
HIGH_LOW = ( 'High/Low' , '' )
HUMIDITY = ( 'Humidity' , '' )
+ LIGHT_DIMMER = ( 'Light Dimmer' , 'Controllable light brightness (0-100%)' )
LIGHT_LEVEL = ( 'Light Level' , '' )
MOISTURE = ( 'Moisture' , '' )
MOVEMENT = ( 'Movement' , '' )
diff --git a/src/hi/apps/entity/migrations/0002_add_integration_metadata.py b/src/hi/apps/entity/migrations/0002_add_integration_metadata.py
new file mode 100644
index 00000000..2419313c
--- /dev/null
+++ b/src/hi/apps/entity/migrations/0002_add_integration_metadata.py
@@ -0,0 +1,23 @@
+# Generated by Django 4.2.15 on 2025-08-15 05:12
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("entity", "0001_initial"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="entity",
+ name="integration_metadata",
+ field=models.JSONField(
+ blank=True,
+ default=dict,
+ help_text="Integration-specific metadata (e.g., HA domain, device capabilities)",
+ verbose_name="Integration Metadata",
+ ),
+ ),
+ ]
diff --git a/src/hi/apps/entity/migrations/0003_rename_integration_metadata_entity_integration_payload.py b/src/hi/apps/entity/migrations/0003_rename_integration_metadata_entity_integration_payload.py
new file mode 100644
index 00000000..e8bae93b
--- /dev/null
+++ b/src/hi/apps/entity/migrations/0003_rename_integration_metadata_entity_integration_payload.py
@@ -0,0 +1,18 @@
+# Generated by Django 4.2.15 on 2025-08-15 20:48
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("entity", "0002_add_integration_metadata"),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name="entity",
+ old_name="integration_metadata",
+ new_name="integration_payload",
+ ),
+ ]
diff --git a/src/hi/apps/entity/migrations/0004_alter_entity_integration_payload.py b/src/hi/apps/entity/migrations/0004_alter_entity_integration_payload.py
new file mode 100644
index 00000000..fa2b1a7c
--- /dev/null
+++ b/src/hi/apps/entity/migrations/0004_alter_entity_integration_payload.py
@@ -0,0 +1,23 @@
+# Generated by Django 4.2.15 on 2025-08-15 20:48
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("entity", "0003_rename_integration_metadata_entity_integration_payload"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="entity",
+ name="integration_payload",
+ field=models.JSONField(
+ blank=True,
+ default=dict,
+ help_text="Integration-specific data (e.g., HA domain, device capabilities)",
+ verbose_name="Integration Payload",
+ ),
+ ),
+ ]
diff --git a/src/hi/apps/entity/models.py b/src/hi/apps/entity/models.py
index 88fb4e4f..e533d08e 100644
--- a/src/hi/apps/entity/models.py
+++ b/src/hi/apps/entity/models.py
@@ -11,7 +11,7 @@ from hi.apps.location.models import (
LocationView,
)
from hi.apps.attribute.models import AttributeModel
-from hi.integrations.models import IntegrationKeyModel
+from hi.integrations.models import IntegrationDetailsModel
from hi.enums import ItemType
from .enums import (
@@ -21,7 +21,7 @@ from .enums import (
)
-class Entity( IntegrationKeyModel, LocationItemModelMixin ):
+class Entity( IntegrationDetailsModel, LocationItemModelMixin ):
"""
- A physical feature, device or software artifact.
- May have a fixed physical location (or can just be part of a collection)
diff --git a/src/hi/apps/event/event_manager.py b/src/hi/apps/event/event_manager.py
index fef0857b..aa1e1eaf 100644
--- a/src/hi/apps/event/event_manager.py
+++ b/src/hi/apps/event/event_manager.py
@@ -16,7 +16,7 @@ from hi.apps.entity.models import EntityState
from hi.apps.security.enums import SecurityLevel
from hi.apps.security.security_mixins import SecurityMixin
-from hi.integrations.integration_key import IntegrationKey
+from hi.integrations.transient_models import IntegrationKey
from .enums import EventType
from .models import AlarmAction, EventClause, EventDefinition, EventHistory
diff --git a/src/hi/apps/event/migrations/0002_add_integration_metadata.py b/src/hi/apps/event/migrations/0002_add_integration_metadata.py
new file mode 100644
index 00000000..ad82ad53
--- /dev/null
+++ b/src/hi/apps/event/migrations/0002_add_integration_metadata.py
@@ -0,0 +1,23 @@
+# Generated by Django 4.2.15 on 2025-08-15 05:12
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("event", "0001_initial"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="eventdefinition",
+ name="integration_metadata",
+ field=models.JSONField(
+ blank=True,
+ default=dict,
+ help_text="Integration-specific metadata (e.g., HA domain, device capabilities)",
+ verbose_name="Integration Metadata",
+ ),
+ ),
+ ]
diff --git a/src/hi/apps/event/migrations/0003_rename_integration_metadata_eventdefinition_integration_payload.py b/src/hi/apps/event/migrations/0003_rename_integration_metadata_eventdefinition_integration_payload.py
new file mode 100644
index 00000000..acc93eac
--- /dev/null
+++ b/src/hi/apps/event/migrations/0003_rename_integration_metadata_eventdefinition_integration_payload.py
@@ -0,0 +1,18 @@
+# Generated by Django 4.2.15 on 2025-08-15 20:48
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("event", "0002_add_integration_metadata"),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name="eventdefinition",
+ old_name="integration_metadata",
+ new_name="integration_payload",
+ ),
+ ]
diff --git a/src/hi/apps/event/migrations/0004_alter_eventdefinition_integration_payload.py b/src/hi/apps/event/migrations/0004_alter_eventdefinition_integration_payload.py
new file mode 100644
index 00000000..7715dac9
--- /dev/null
+++ b/src/hi/apps/event/migrations/0004_alter_eventdefinition_integration_payload.py
@@ -0,0 +1,26 @@
+# Generated by Django 4.2.15 on 2025-08-15 20:48
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ (
+ "event",
+ "0003_rename_integration_metadata_eventdefinition_integration_payload",
+ ),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="eventdefinition",
+ name="integration_payload",
+ field=models.JSONField(
+ blank=True,
+ default=dict,
+ help_text="Integration-specific data (e.g., HA domain, device capabilities)",
+ verbose_name="Integration Payload",
+ ),
+ ),
+ ]
diff --git a/src/hi/apps/event/models.py b/src/hi/apps/event/models.py
index 5a69a4ed..35a44cca 100644
--- a/src/hi/apps/event/models.py
+++ b/src/hi/apps/event/models.py
@@ -5,12 +5,12 @@ from hi.apps.control.models import Controller
from hi.apps.entity.models import EntityState
from hi.apps.security.enums import SecurityLevel
-from hi.integrations.models import IntegrationKeyModel
+from hi.integrations.models import IntegrationDetailsModel
from .enums import EventType
-class EventDefinition( IntegrationKeyModel ):
+class EventDefinition( IntegrationDetailsModel ):
name = models.CharField(
'Name',
diff --git a/src/hi/apps/event/tests/test_models.py b/src/hi/apps/event/tests/test_models.py
index 0a550e55..42dd8f6e 100644
--- a/src/hi/apps/event/tests/test_models.py
+++ b/src/hi/apps/event/tests/test_models.py
@@ -24,7 +24,7 @@ class TestEventDefinition(BaseTestCase):
integration_name='test_integration'
)
- # Should inherit integration key fields from IntegrationKeyModel
+ # Should inherit integration key fields from IntegrationDetailsModel
self.assertEqual(event_def.integration_id, 'test_id')
self.assertEqual(event_def.integration_name, 'test_integration')
return
diff --git a/src/hi/apps/model_helper.py b/src/hi/apps/model_helper.py
index 1e35adef..5b89f7a0 100644
--- a/src/hi/apps/model_helper.py
+++ b/src/hi/apps/model_helper.py
@@ -18,7 +18,7 @@ from hi.apps.security.enums import SecurityLevel
from hi.apps.sense.enums import SensorType
from hi.apps.sense.models import Sensor
-from hi.integrations.integration_key import IntegrationKey
+from hi.integrations.transient_models import IntegrationKey
class HiModelHelper:
@@ -272,6 +272,25 @@ class HiModelHelper:
value_range_str = json.dumps( name_label_dict ),
)
+ @classmethod
+ def create_light_dimmer_controller( cls,
+ entity : Entity,
+ integration_key : IntegrationKey = None,
+ name : str = None,
+ is_sensed : bool = True ) -> Controller:
+ if not name:
+ name = f'{entity.name} Dimmer'
+ # Light dimmer range: 0-100 (percentage)
+ value_range = {'min': 0, 'max': 100}
+ return cls.create_controller(
+ entity = entity,
+ entity_state_type = EntityStateType.LIGHT_DIMMER,
+ name = name,
+ is_sensed = is_sensed,
+ integration_key = integration_key,
+ value_range_str = json.dumps( value_range ),
+ )
+
@classmethod
def create_sensor( cls,
entity : Entity,
diff --git a/src/hi/apps/sense/migrations/0002_add_integration_metadata.py b/src/hi/apps/sense/migrations/0002_add_integration_metadata.py
new file mode 100644
index 00000000..de23657b
--- /dev/null
+++ b/src/hi/apps/sense/migrations/0002_add_integration_metadata.py
@@ -0,0 +1,23 @@
+# Generated by Django 4.2.15 on 2025-08-15 05:12
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("sense", "0001_initial"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="sensor",
+ name="integration_metadata",
+ field=models.JSONField(
+ blank=True,
+ default=dict,
+ help_text="Integration-specific metadata (e.g., HA domain, device capabilities)",
+ verbose_name="Integration Metadata",
+ ),
+ ),
+ ]
diff --git a/src/hi/apps/sense/migrations/0003_rename_integration_metadata_sensor_integration_payload.py b/src/hi/apps/sense/migrations/0003_rename_integration_metadata_sensor_integration_payload.py
new file mode 100644
index 00000000..b293d055
--- /dev/null
+++ b/src/hi/apps/sense/migrations/0003_rename_integration_metadata_sensor_integration_payload.py
@@ -0,0 +1,18 @@
+# Generated by Django 4.2.15 on 2025-08-15 20:48
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("sense", "0002_add_integration_metadata"),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name="sensor",
+ old_name="integration_metadata",
+ new_name="integration_payload",
+ ),
+ ]
diff --git a/src/hi/apps/sense/migrations/0004_alter_sensor_integration_payload.py b/src/hi/apps/sense/migrations/0004_alter_sensor_integration_payload.py
new file mode 100644
index 00000000..cd6a03e7
--- /dev/null
+++ b/src/hi/apps/sense/migrations/0004_alter_sensor_integration_payload.py
@@ -0,0 +1,23 @@
+# Generated by Django 4.2.15 on 2025-08-15 20:48
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("sense", "0003_rename_integration_metadata_sensor_integration_payload"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="sensor",
+ name="integration_payload",
+ field=models.JSONField(
+ blank=True,
+ default=dict,
+ help_text="Integration-specific data (e.g., HA domain, device capabilities)",
+ verbose_name="Integration Payload",
+ ),
+ ),
+ ]
diff --git a/src/hi/apps/sense/models.py b/src/hi/apps/sense/models.py
index 9fa78e4b..b5b24c96 100644
--- a/src/hi/apps/sense/models.py
+++ b/src/hi/apps/sense/models.py
@@ -4,12 +4,12 @@ from django.db import models
from hi.apps.entity.models import EntityState
-from hi.integrations.models import IntegrationKeyModel
+from hi.integrations.models import IntegrationDetailsModel
from .enums import SensorType
-class Sensor( IntegrationKeyModel ):
+class Sensor( IntegrationDetailsModel ):
"""
- Represents an observed state of an entity.
- Will sense exactly one EntityState
diff --git a/src/hi/apps/sense/sensor_response_manager.py b/src/hi/apps/sense/sensor_response_manager.py
index 56973515..98d62e1c 100644
--- a/src/hi/apps/sense/sensor_response_manager.py
+++ b/src/hi/apps/sense/sensor_response_manager.py
@@ -9,7 +9,7 @@ from hi.apps.common.singleton import Singleton
from hi.apps.event.event_mixins import EventMixin
from hi.apps.event.transient_models import EntityStateTransition
-from hi.integrations.integration_key import IntegrationKey
+from hi.integrations.transient_models import IntegrationKey
from .models import Sensor
from .sensor_history_manager import SensorHistoryMixin
diff --git a/src/hi/apps/sense/tests/test_models.py b/src/hi/apps/sense/tests/test_models.py
index 4f6a908c..3fcf18cb 100644
--- a/src/hi/apps/sense/tests/test_models.py
+++ b/src/hi/apps/sense/tests/test_models.py
@@ -83,7 +83,7 @@ class TestSensor(BaseTestCase):
integration_name='test_integration'
)
- # Should inherit integration key fields from IntegrationKeyModel
+ # Should inherit integration key fields from IntegrationDetailsModel
self.assertEqual(sensor.integration_id, 'sensor_123')
self.assertEqual(sensor.integration_name, 'test_integration')
return
diff --git a/src/hi/apps/sense/transient_models.py b/src/hi/apps/sense/transient_models.py
index 49132139..22bf8850 100644
--- a/src/hi/apps/sense/transient_models.py
+++ b/src/hi/apps/sense/transient_models.py
@@ -5,7 +5,7 @@ from typing import Dict
from hi.apps.entity.enums import EntityStateValue
-from hi.integrations.integration_key import IntegrationKey
+from hi.integrations.transient_models import IntegrationKey
from .models import Sensor, SensorHistory
diff --git a/src/hi/integrations/integration_controller.py b/src/hi/integrations/integration_controller.py
index fa3ff3a8..5c3336b5 100644
--- a/src/hi/integrations/integration_controller.py
+++ b/src/hi/integrations/integration_controller.py
@@ -1,10 +1,10 @@
-from .integration_key import IntegrationKey
+from .transient_models import IntegrationDetails
from .transient_models import IntegrationControlResult
class IntegrationController:
def do_control( self,
- integration_key : IntegrationKey,
- control_value : str ) -> IntegrationControlResult:
+ integration_details : IntegrationDetails,
+ control_value : str ) -> IntegrationControlResult:
raise NotImplementedError('Subclasses must override this method')
diff --git a/src/hi/integrations/integration_key.py b/src/hi/integrations/integration_key.py
deleted file mode 100644
index 76fb70a7..00000000
--- a/src/hi/integrations/integration_key.py
+++ /dev/null
@@ -1,41 +0,0 @@
-from dataclasses import dataclass
-
-
-@dataclass
-class IntegrationKey:
- """ Internal identifier to help map to/from an integration's external names/identifiers """
-
- integration_id : str # Internally defined unique identifier for the integration source
- integration_name : str # Name or identifier that is used by the external source.
-
- def __post_init__(self):
- # Want to make matching more robust, so only
- self.integration_id = self.integration_id.lower()
- self.integration_name = self.integration_name.lower()
- return
-
- def __str__(self):
- return self.integration_key_str
-
- def __eq__(self, other):
- if isinstance(other, IntegrationKey):
- return self.integration_key_str == other.integration_key_str
- return False
-
- def __hash__(self):
- return hash(self.integration_key_str)
-
- @property
- def integration_key_str(self):
- return f'{self.integration_id}.{self.integration_name}'
-
- @classmethod
- def from_string( cls, a_string : str ):
- prefix, suffix = a_string.split( '.', 1 )
- return IntegrationKey(
- integration_id = prefix,
- integration_name = suffix,
- )
-
-
-
diff --git a/src/hi/integrations/integration_manager.py b/src/hi/integrations/integration_manager.py
index 6b71f4cf..5721e267 100644
--- a/src/hi/integrations/integration_manager.py
+++ b/src/hi/integrations/integration_manager.py
@@ -17,7 +17,7 @@ from .enums import IntegrationAttributeType
from .forms import IntegrationAttributeFormSet
from .integration_data import IntegrationData
from .integration_gateway import IntegrationGateway
-from .integration_key import IntegrationKey
+from .transient_models import IntegrationKey
from .models import Integration, IntegrationAttribute
from .transient_models import IntegrationMetaData
diff --git a/src/hi/integrations/managers.py b/src/hi/integrations/managers.py
index 2d47ee63..e56d1074 100644
--- a/src/hi/integrations/managers.py
+++ b/src/hi/integrations/managers.py
@@ -3,10 +3,10 @@ from typing import Sequence
from django.db import models
from django.db.models import Q
-from .integration_key import IntegrationKey
+from .transient_models import IntegrationKey
-class IntegrationKeyManager(models.Manager):
+class IntegrationDetailsManager(models.Manager):
def filter_by_integration_key( self, integration_key : IntegrationKey ):
return self.filter( integration_id = integration_key.integration_id,
diff --git a/src/hi/integrations/models.py b/src/hi/integrations/models.py
index cb7e0083..8b0e5991 100644
--- a/src/hi/integrations/models.py
+++ b/src/hi/integrations/models.py
@@ -4,8 +4,8 @@ from django.db import models
from hi.apps.attribute.models import AttributeModel
-from .integration_key import IntegrationKey
-from .managers import IntegrationKeyManager
+from .transient_models import IntegrationKey, IntegrationDetails
+from .managers import IntegrationDetailsManager
class Integration( models.Model ):
@@ -64,12 +64,12 @@ class IntegrationAttribute( AttributeModel ):
return 'integration/attributes/'
-class IntegrationKeyModel( models.Model ):
+class IntegrationDetailsModel( models.Model ):
"""
For use in DB objects that need to be associated with an integration
device, sensor, controller, attribute, etc.
"""
- objects = IntegrationKeyManager()
+ objects = IntegrationDetailsManager()
class Meta:
abstract = True
@@ -84,6 +84,12 @@ class IntegrationKeyModel( models.Model ):
max_length = 128,
null = True, blank = True,
)
+ integration_payload = models.JSONField(
+ 'Integration Payload',
+ default = dict,
+ blank = True,
+ help_text = 'Integration-specific data (e.g., HA domain, device capabilities)',
+ )
@property
def integration_key(self) -> IntegrationKey:
@@ -101,3 +107,29 @@ class IntegrationKeyModel( models.Model ):
self.integration_id = integration_key.integration_id
self.integration_name = integration_key.integration_name
return
+
+ def get_integration_details(self) -> IntegrationDetails:
+ return IntegrationDetails(
+ key = self.integration_key,
+ payload = self.integration_payload,
+ )
+
+ def update_integration_payload(self, new_payload: dict) -> list:
+ """
+ Update integration payload and return list of changed fields.
+ Only reports changes to existing fields (ignores new fields).
+ Returns list of strings describing changes, empty if no existing values changed.
+ """
+ old_payload = self.integration_payload or {}
+ changed_fields = []
+
+ # Check for changes to existing fields only
+ for key, new_value in new_payload.items():
+ if key in old_payload and old_payload[key] != new_value:
+ changed_fields.append(f'{key}: {old_payload[key]} -> {new_value}')
+
+ # Always update payload (even if no existing fields changed)
+ self.integration_payload = new_payload
+ self.save()
+
+ return changed_fields
diff --git a/src/hi/integrations/transient_models.py b/src/hi/integrations/transient_models.py
index 9df67f6e..873f49ad 100644
--- a/src/hi/integrations/transient_models.py
+++ b/src/hi/integrations/transient_models.py
@@ -1,5 +1,5 @@
from dataclasses import dataclass
-from typing import List
+from typing import Dict, List, Optional
from .enums import IntegrationAttributeType
@@ -22,4 +22,47 @@ class IntegrationControlResult:
@property
def has_errors(self):
return bool( self.error_list )
+
+
+@dataclass
+class IntegrationKey:
+ """ Internal identifier to help map to/from an integration's external names/identifiers """
+
+ integration_id : str # Internally defined unique identifier for the integration source
+ integration_name : str # Name or identifier that is used by the external source.
+
+ def __post_init__(self):
+ # Want to make matching more robust, so only
+ self.integration_id = self.integration_id.lower()
+ self.integration_name = self.integration_name.lower()
+ return
+ def __str__(self):
+ return self.integration_key_str
+
+ def __eq__(self, other):
+ if isinstance(other, IntegrationKey):
+ return self.integration_key_str == other.integration_key_str
+ return False
+
+ def __hash__(self):
+ return hash(self.integration_key_str)
+
+ @property
+ def integration_key_str(self):
+ return f'{self.integration_id}.{self.integration_name}'
+
+ @classmethod
+ def from_string( cls, a_string : str ):
+ prefix, suffix = a_string.split( '.', 1 )
+ return IntegrationKey(
+ integration_id = prefix,
+ integration_name = suffix,
+ )
+
+
+@dataclass
+class IntegrationDetails:
+ """ Integration key plus data for cases where additional integration-specific data is needed """
+ key : IntegrationKey
+ payload : Optional[Dict] = None
diff --git a/src/hi/services/hass/hass_client.py b/src/hi/services/hass/hass_client.py
index feca95f7..62d7a917 100644
--- a/src/hi/services/hass/hass_client.py
+++ b/src/hi/services/hass/hass_client.py
@@ -16,6 +16,8 @@ class HassClient:
API_BASE_URL = 'api_base_url'
API_TOKEN = 'api_token'
+ TRACE = False # For debugging
+
def __init__( self, api_options : Dict[ str, str ] ):
self._api_base_url = api_options.get( self.API_BASE_URL )
@@ -37,7 +39,8 @@ class HassClient:
url = f'{self._api_base_url}/api/states'
response = get( url, headers = self._headers )
data = json.loads(response.text)
- logger.debug( f'HAss Response = {response.text}' )
+ if self.TRACE:
+ logger.debug( f'HAss Response = {response.text}' )
return [ HassConverter.create_hass_state(x) for x in data ]
def set_state( self, entity_id: str, state: str, attributes: dict = None ) -> dict:
@@ -54,4 +57,31 @@ class HassClient:
return response.json()
+ def call_service( self, domain: str, service: str, hass_state_id: str, service_data: dict = None ):
+ """
+ Call a Home Assistant service for a specific HassState.
+
+ Args:
+ domain: The domain (e.g., 'light', 'switch')
+ service: The service name (e.g., 'turn_on', 'turn_off')
+ hass_state_id: The HassState identifier (e.g., 'light.switch_name')
+ service_data: Additional service data (optional)
+
+ Returns:
+ Response object
+ """
+ url = f'{self._api_base_url}/api/services/{domain}/{service}'
+ data = {
+ 'entity_id': hass_state_id,
+ }
+ if service_data:
+ data.update(service_data)
+
+ response = post( url, json = data, headers = self._headers )
+ if response.status_code not in [200, 201]:
+ raise ValueError( f"Failed to call service: {response.status_code} {response.text}" )
+
+ logger.debug( f'HAss call_service: {domain}.{service} for {hass_state_id}, response={response.status_code}' )
+ return response
+
diff --git a/src/hi/services/hass/hass_controller.py b/src/hi/services/hass/hass_controller.py
index 1329f566..fa7fbd53 100644
--- a/src/hi/services/hass/hass_controller.py
+++ b/src/hi/services/hass/hass_controller.py
@@ -1,7 +1,7 @@
import logging
from hi.integrations.integration_controller import IntegrationController
-from hi.integrations.integration_key import IntegrationKey
+from hi.integrations.transient_models import IntegrationDetails
from hi.integrations.transient_models import IntegrationControlResult
from .hass_converter import HassConverter
@@ -13,34 +13,524 @@ logger = logging.getLogger(__name__)
class HassController( IntegrationController, HassMixin ):
def do_control( self,
- integration_key : IntegrationKey,
- control_value : str ) -> IntegrationControlResult:
+ integration_details : IntegrationDetails,
+ control_value : str ) -> IntegrationControlResult:
+ logger.debug( f'HAss do_control ENTRY: integration_details={integration_details}, control_value={control_value}' )
try:
- entity_id = integration_key.integration_name
+ entity_id = integration_details.key.integration_name
+ domain_payload = integration_details.payload or {}
+ logger.debug( f'HAss do_control entity_id: {entity_id}, payload: {domain_payload}' )
+
hass_state_value = HassConverter.hass_entity_id_to_state_value_str(
hass_entity_id = entity_id,
hi_value = control_value,
)
+ logger.debug( f'HAss do_control converted value: {hass_state_value}' )
- response = self.hass_manager().hass_client.set_state(
- entity_id = entity_id,
- state = hass_state_value,
+ return self._do_control_with_services( entity_id, control_value, hass_state_value, domain_payload )
+ except Exception as e:
+ logger.warning( f'Exception in HAss do_control: {e}' )
+ return IntegrationControlResult(
+ new_value = None,
+ error_list = [ str(e) ],
)
- if response.status_code == 200:
- error_list = list()
- else:
- error_list = [ f'Bad HAss response. Status code = {response.status_code}' ]
-
- logger.debug( f'HAss set state: {entity_id}={hass_state_value}, response={response}' )
+ def _do_control_with_set_state( self, hass_state_id: str, control_value: str, hass_state_value: str ) -> IntegrationControlResult:
+ """
+ Legacy method using Home Assistant set_state API.
+
+ Note: This method updates HA's internal state but may not actually
+ control physical devices. Kept for debugging and special use cases.
+ """
+ logger.debug( f'HAss attempting set state: {hass_state_id}={hass_state_value}' )
+
+ response_data = self.hass_manager().hass_client.set_state(
+ entity_id = hass_state_id,
+ state = hass_state_value,
+ )
+
+ # If we get here, the HTTP call succeeded (set_state raises exception on failure)
+ error_list = list()
+ logger.debug( f'HAss set state SUCCESS: {hass_state_id}={hass_state_value}, response_data={response_data}' )
+ return IntegrationControlResult(
+ new_value = control_value,
+ error_list = error_list,
+ )
+
+ def _do_control_with_services( self,
+ hass_state_id : str,
+ control_value : str,
+ hass_state_value : str,
+ domain_payload : dict ) -> IntegrationControlResult:
+ """Use Home Assistant service calls for device control (recommended approach)"""
+
+ # Extract domain from payload (more reliable than parsing entity_id)
+ domain = domain_payload.get('domain')
+ if not domain:
+ # Fallback to parsing from entity_id if payload missing
+ if '.' not in hass_state_id:
+ logger.warning( f'Invalid hass_state_id format and no domain payload: {hass_state_id}' )
+ return IntegrationControlResult(
+ new_value = None,
+ error_list = [f'Invalid entity_id format: {hass_state_id}'],
+ )
+ domain = hass_state_id.split('.', 1)[0]
+ logger.warning( f'Missing domain payload for {hass_state_id}, using parsed domain: {domain}' )
+
+ # Use payload-based service routing if available, otherwise best-effort
+ if domain_payload:
+ return self._control_device_with_payload( domain, hass_state_id, control_value, hass_state_value, domain_payload )
+ else:
+ return self._control_device_best_effort( domain, hass_state_id, control_value, hass_state_value )
+
+ def _control_on_off_device( self, domain: str, hass_state_id: str, control_value: str, hass_state_value: str ) -> IntegrationControlResult:
+ """Handle on/off control for lights, switches, and similar devices"""
+ logger.debug( f'HAss attempting service call for {domain}: {hass_state_id}={control_value}' )
+
+ # Determine service based on control value
+ if control_value.lower() in ['on', 'true', '1']:
+ service = 'turn_on'
+ elif control_value.lower() in ['off', 'false', '0']:
+ service = 'turn_off'
+ else:
+ logger.warning( f'Unknown {domain} control value "{control_value}"' )
return IntegrationControlResult(
- new_value = control_value,
- error_list = error_list,
+ new_value = None,
+ error_list = [f'Unknown control value: {control_value}'],
)
+
+ # Call the Home Assistant service
+ self.hass_manager().hass_client.call_service(
+ domain = domain,
+ service = service,
+ hass_state_id = hass_state_id,
+ )
+
+ error_list = list()
+ logger.debug( f'HAss service call SUCCESS: {domain}.{service} for {hass_state_id}' )
+ return IntegrationControlResult(
+ new_value = control_value,
+ error_list = error_list,
+ )
+ def _control_device_best_effort( self, domain: str, hass_state_id: str, control_value: str, hass_state_value: str ) -> IntegrationControlResult:
+ """
+ Best-effort device control when payload is missing.
+ Uses standard Home Assistant service patterns based on domain and control value.
+ """
+ logger.debug( f'HAss best-effort control: {domain} {hass_state_id}={control_value}' )
+
+ try:
+ # Handle numeric controls for known domains
+ if self._is_numeric_value( control_value ):
+ return self._control_numeric_best_effort( domain, hass_state_id, control_value )
+
+ # Handle on/off/open/close controls
+ return self._control_on_off_best_effort( domain, hass_state_id, control_value )
+
except Exception as e:
- logger.warning( f'Exception in HAss do_control: {e}' )
+ logger.warning( f'Best-effort control failed for {hass_state_id}: {e}' )
return IntegrationControlResult(
new_value = None,
- error_list = [ str(e) ],
+ error_list = [f'Best-effort control failed: {str(e)}'],
+ )
+
+ def _is_numeric_value( self, control_value: str ) -> bool:
+ """Check if control value is numeric"""
+ try:
+ float(control_value)
+ return True
+ except (ValueError, TypeError):
+ return False
+
+ def _control_on_off_best_effort( self, domain: str, hass_state_id: str, control_value: str ) -> IntegrationControlResult:
+ """Best-effort on/off/open/close control based on standard HA patterns"""
+ logger.debug( f'HAss best-effort on/off control: {domain} {hass_state_id}={control_value}' )
+
+ # Determine service based on control value and domain
+ control_lower = control_value.lower()
+
+ if control_lower in ['on', 'true', '1']:
+ service = 'turn_on'
+ elif control_lower in ['off', 'false', '0']:
+ service = 'turn_off'
+ elif control_lower in ['open']:
+ if domain == 'cover':
+ service = 'open_cover'
+ elif domain == 'lock':
+ service = 'unlock'
+ else:
+ service = 'turn_on' # Fallback
+ elif control_lower in ['close']:
+ if domain == 'cover':
+ service = 'close_cover'
+ elif domain == 'lock':
+ service = 'lock'
+ else:
+ service = 'turn_off' # Fallback
+ else:
+ logger.warning( f'Unknown control value "{control_value}" for best-effort control of {hass_state_id}' )
+ return IntegrationControlResult(
+ new_value = None,
+ error_list = [f'Unknown control value: {control_value}'],
+ )
+
+ # Call the Home Assistant service
+ self.hass_manager().hass_client.call_service(
+ domain = domain,
+ service = service,
+ hass_state_id = hass_state_id,
+ )
+
+ logger.debug( f'HAss best-effort service call SUCCESS: {domain}.{service} for {hass_state_id}' )
+ return IntegrationControlResult(
+ new_value = control_value,
+ error_list = [],
+ )
+
+ def _control_numeric_best_effort( self, domain: str, hass_state_id: str, control_value: str ) -> IntegrationControlResult:
+ """Best-effort numeric control based on common HA patterns"""
+ logger.debug( f'HAss best-effort numeric control: {domain} {hass_state_id}={control_value}' )
+
+ try:
+ numeric_value = float(control_value)
+
+ # Light brightness (0-100%)
+ if domain == 'light':
+ brightness_pct = int(numeric_value)
+ if not (0 <= brightness_pct <= 100):
+ return IntegrationControlResult(
+ new_value = None,
+ error_list = [f'Invalid brightness value: {brightness_pct} (must be 0-100)'],
+ )
+
+ if brightness_pct == 0:
+ service = 'turn_off'
+ service_data = None
+ else:
+ service = 'turn_on'
+ service_data = {'brightness_pct': brightness_pct}
+
+ self.hass_manager().hass_client.call_service(
+ domain = domain,
+ service = service,
+ hass_state_id = hass_state_id,
+ service_data = service_data,
+ )
+
+ logger.debug( f'HAss best-effort light control SUCCESS: {domain}.{service} for {hass_state_id}' )
+ return IntegrationControlResult(
+ new_value = str(brightness_pct),
+ error_list = [],
+ )
+
+ # Climate temperature
+ elif domain == 'climate':
+ self.hass_manager().hass_client.call_service(
+ domain = domain,
+ service = 'set_temperature',
+ hass_state_id = hass_state_id,
+ service_data = {'temperature': numeric_value},
+ )
+
+ logger.debug( f'HAss best-effort climate control SUCCESS: climate.set_temperature for {hass_state_id}' )
+ return IntegrationControlResult(
+ new_value = str(numeric_value),
+ error_list = [],
+ )
+
+ # Cover position (0-100%)
+ elif domain == 'cover':
+ position_pct = int(numeric_value)
+ if not (0 <= position_pct <= 100):
+ return IntegrationControlResult(
+ new_value = None,
+ error_list = [f'Invalid position value: {position_pct} (must be 0-100)'],
+ )
+
+ self.hass_manager().hass_client.call_service(
+ domain = domain,
+ service = 'set_cover_position',
+ hass_state_id = hass_state_id,
+ service_data = {'position': position_pct},
+ )
+
+ logger.debug( f'HAss best-effort cover control SUCCESS: cover.set_cover_position for {hass_state_id}' )
+ return IntegrationControlResult(
+ new_value = str(position_pct),
+ error_list = [],
+ )
+
+ # Media player volume (0.0-1.0)
+ elif domain == 'media_player':
+ if not (0.0 <= numeric_value <= 1.0):
+ return IntegrationControlResult(
+ new_value = None,
+ error_list = [f'Invalid volume value: {numeric_value} (must be 0.0-1.0)'],
+ )
+
+ self.hass_manager().hass_client.call_service(
+ domain = domain,
+ service = 'volume_set',
+ hass_state_id = hass_state_id,
+ service_data = {'volume_level': numeric_value},
+ )
+
+ logger.debug( f'HAss best-effort media_player control SUCCESS: media_player.volume_set for {hass_state_id}' )
+ return IntegrationControlResult(
+ new_value = str(numeric_value),
+ error_list = [],
+ )
+
+ # Other domains - try generic approach
+ else:
+ logger.warning( f'No best-effort numeric control pattern for domain {domain}, entity {hass_state_id}' )
+ return IntegrationControlResult(
+ new_value = None,
+ error_list = [f'No numeric control pattern for domain: {domain}'],
+ )
+
+ except ValueError:
+ return IntegrationControlResult(
+ new_value = None,
+ error_list = [f'Invalid numeric value: {control_value}'],
+ )
+
+ def _control_device_with_payload( self, domain: str, hass_state_id: str, control_value: str, hass_state_value: str, domain_payload: dict ) -> IntegrationControlResult:
+ """Use stored payload to control device directly"""
+ logger.debug( f'HAss payload-based control: {domain} {hass_state_id}={control_value}, payload={domain_payload}' )
+
+ # Check if device is controllable
+ if not domain_payload.get('is_controllable', False):
+ logger.warning( f'Device {hass_state_id} is not controllable, attempting best-effort control' )
+ return self._control_device_best_effort( domain, hass_state_id, control_value, hass_state_value )
+
+ # Handle complex numeric controls (brightness, temperature, volume, etc.)
+ if self._is_numeric_control( control_value, domain_payload ):
+ return self._control_numeric_parameter_device( domain, hass_state_id, control_value, domain_payload )
+
+ # Handle on/off control
+ if control_value.lower() in ['on', 'true', '1']:
+ service = domain_payload.get('on_service')
+ if not service:
+ logger.warning( f'No on_service defined in payload for {hass_state_id}, using best-effort control' )
+ return self._control_device_best_effort( domain, hass_state_id, control_value, hass_state_value )
+ elif control_value.lower() in ['off', 'false', '0']:
+ service = domain_payload.get('off_service')
+ if not service:
+ logger.warning( f'No off_service defined in payload for {hass_state_id}, using best-effort control' )
+ return self._control_device_best_effort( domain, hass_state_id, control_value, hass_state_value )
+ elif control_value.lower() in ['open']:
+ service = domain_payload.get('open_service')
+ if not service:
+ logger.warning( f'No open_service defined in payload for {hass_state_id}, using best-effort control' )
+ return self._control_device_best_effort( domain, hass_state_id, control_value, hass_state_value )
+ elif control_value.lower() in ['close']:
+ service = domain_payload.get('close_service')
+ if not service:
+ logger.warning( f'No close_service defined in payload for {hass_state_id}, using best-effort control' )
+ return self._control_device_best_effort( domain, hass_state_id, control_value, hass_state_value )
+ else:
+ logger.warning( f'Unknown control value "{control_value}" for {hass_state_id}' )
+ return IntegrationControlResult(
+ new_value = None,
+ error_list = [f'Unknown control value: {control_value}'],
+ )
+
+ # Call the Home Assistant service
+ self.hass_manager().hass_client.call_service(
+ domain = domain,
+ service = service,
+ hass_state_id = hass_state_id,
+ )
+
+ logger.debug( f'HAss service call SUCCESS: {domain}.{service} for {hass_state_id}' )
+ return IntegrationControlResult(
+ new_value = control_value,
+ error_list = [],
+ )
+
+ def _is_numeric_control( self, control_value: str, domain_payload: dict ) -> bool:
+ """Check if control value should be handled as numeric parameter"""
+ try:
+ # Must be a valid numeric value
+ float(control_value)
+
+ # Must have either brightness support or set_service for numeric parameters
+ return ( domain_payload.get('supports_brightness', False)
+ or domain_payload.get('set_service') is not None )
+ except (ValueError, TypeError):
+ return False
+
+ def _control_numeric_parameter_device( self,
+ domain : str,
+ hass_state_id : str,
+ control_value : str,
+ domain_payload : dict ) -> IntegrationControlResult:
+ """Handle numeric parameter controls (brightness, temperature, volume, position, etc.)"""
+ try:
+ numeric_value = float(control_value)
+
+ # Handle brightness control (0-100%)
+ if domain_payload.get('supports_brightness', False):
+ return self._control_brightness_value( domain, hass_state_id, numeric_value, domain_payload )
+
+ # Handle temperature control
+ elif 'temperature' in domain_payload.get('parameters', {}):
+ return self._control_temperature_value( domain, hass_state_id, numeric_value, domain_payload )
+
+ # Handle volume control
+ elif 'volume_level' in domain_payload.get('parameters', {}):
+ return self._control_volume_value( domain, hass_state_id, numeric_value, domain_payload )
+
+ # Handle position control (covers, etc.)
+ elif 'position' in domain_payload.get('parameters', {}):
+ return self._control_position_value( domain, hass_state_id, numeric_value, domain_payload )
+
+ # Generic set_service fallback
+ elif domain_payload.get('set_service'):
+ service = domain_payload.get('set_service')
+ # Use the numeric value directly - service will determine parameter name
+ service_data = {domain.rstrip('s'): numeric_value} # e.g., climate -> temperature
+
+ self.hass_manager().hass_client.call_service(
+ domain = domain,
+ service = service,
+ hass_state_id = hass_state_id,
+ service_data = service_data,
+ )
+
+ logger.debug( f'HAss numeric control SUCCESS: {domain}.{service} for {hass_state_id} value={numeric_value}' )
+ return IntegrationControlResult(
+ new_value = control_value,
+ error_list = [],
+ )
+
+ else:
+ logger.warning( f'No numeric parameter handling defined for {hass_state_id}' )
+ return IntegrationControlResult(
+ new_value = None,
+ error_list = ['No numeric parameter handling defined'],
+ )
+
+ except ValueError:
+ logger.warning( f'Invalid numeric control value: {control_value}' )
+ return IntegrationControlResult(
+ new_value = None,
+ error_list = [f'Invalid numeric value: {control_value}'],
+ )
+
+ def _control_brightness_value( self, domain: str, hass_state_id: str, brightness: float, domain_payload: dict ) -> IntegrationControlResult:
+ """Handle brightness/dimmer control (0-100%)"""
+ brightness_pct = int(brightness)
+ if not (0 <= brightness_pct <= 100):
+ logger.warning( f'Invalid brightness value {brightness} for {hass_state_id}' )
+ return IntegrationControlResult(
+ new_value = None,
+ error_list = [f'Invalid brightness value: {brightness}'],
+ )
+
+ if brightness_pct == 0:
+ # Turn off for 0% brightness
+ service = domain_payload.get('off_service')
+ service_data = None
+ else:
+ # Turn on with brightness
+ service = domain_payload.get('on_service')
+ service_data = {'brightness_pct': brightness_pct}
+
+ if not service:
+ logger.warning( f'No appropriate service defined in payload for brightness control of {hass_state_id}' )
+ return IntegrationControlResult(
+ new_value = None,
+ error_list = ['No service defined for brightness control'],
+ )
+
+ # Call the Home Assistant service
+ self.hass_manager().hass_client.call_service(
+ domain = domain,
+ service = service,
+ hass_state_id = hass_state_id,
+ service_data = service_data,
+ )
+
+ logger.debug( f'HAss brightness control SUCCESS: {domain}.{service} for {hass_state_id} brightness={brightness_pct}%' )
+ return IntegrationControlResult(
+ new_value = str(brightness_pct),
+ error_list = [],
+ )
+
+ def _control_temperature_value( self, domain: str, hass_state_id: str, temperature: float, domain_payload: dict ) -> IntegrationControlResult:
+ """Handle temperature control for thermostats"""
+ service = domain_payload.get('set_service')
+ if not service:
+ logger.warning( f'No set_service defined for temperature control of {hass_state_id}' )
+ return IntegrationControlResult(
+ new_value = None,
+ error_list = ['No temperature service defined'],
+ )
+
+ # Call the Home Assistant service
+ self.hass_manager().hass_client.call_service(
+ domain = domain,
+ service = service,
+ hass_state_id = hass_state_id,
+ service_data = {'temperature': temperature},
+ )
+
+ logger.debug( f'HAss temperature control SUCCESS: {domain}.{service} for {hass_state_id} temperature={temperature}' )
+ return IntegrationControlResult(
+ new_value = str(temperature),
+ error_list = [],
+ )
+
+ def _control_volume_value( self, domain: str, hass_state_id: str, volume: float, domain_payload: dict ) -> IntegrationControlResult:
+ """Handle volume control for media players (0.0-1.0)"""
+ if not (0.0 <= volume <= 1.0):
+ logger.warning( f'Invalid volume value {volume} for {hass_state_id} (must be 0.0-1.0)' )
+ return IntegrationControlResult(
+ new_value = None,
+ error_list = [f'Invalid volume value: {volume} (must be 0.0-1.0)'],
+ )
+
+ service = domain_payload.get('set_service', 'volume_set')
+
+ # Call the Home Assistant service
+ self.hass_manager().hass_client.call_service(
+ domain = domain,
+ service = service,
+ hass_state_id = hass_state_id,
+ service_data = {'volume_level': volume},
+ )
+
+ logger.debug( f'HAss volume control SUCCESS: {domain}.{service} for {hass_state_id} volume={volume}' )
+ return IntegrationControlResult(
+ new_value = str(volume),
+ error_list = [],
+ )
+
+ def _control_position_value( self, domain: str, hass_state_id: str, position: float, domain_payload: dict ) -> IntegrationControlResult:
+ """Handle position control for covers (0-100%)"""
+ position_pct = int(position)
+ if not (0 <= position_pct <= 100):
+ logger.warning( f'Invalid position value {position} for {hass_state_id} (must be 0-100)' )
+ return IntegrationControlResult(
+ new_value = None,
+ error_list = [f'Invalid position value: {position} (must be 0-100)'],
)
+
+ service = domain_payload.get('set_service', 'set_cover_position')
+
+ # Call the Home Assistant service
+ self.hass_manager().hass_client.call_service(
+ domain = domain,
+ service = service,
+ hass_state_id = hass_state_id,
+ service_data = {'position': position_pct},
+ )
+
+ logger.debug( f'HAss position control SUCCESS: {domain}.{service} for {hass_state_id} position={position_pct}%' )
+ return IntegrationControlResult(
+ new_value = str(position_pct),
+ error_list = [],
+ )
diff --git a/src/hi/services/hass/hass_converter.py b/src/hi/services/hass/hass_converter.py
index 2797663e..469353a4 100644
--- a/src/hi/services/hass/hass_converter.py
+++ b/src/hi/services/hass/hass_converter.py
@@ -9,6 +9,7 @@ from hi.apps.attribute.enums import (
AttributeValueType,
)
from hi.apps.entity.enums import (
+ EntityStateType,
EntityType,
EntityStateValue,
HumidityUnit,
@@ -17,7 +18,7 @@ from hi.apps.entity.enums import (
from hi.apps.entity.models import Entity, EntityAttribute, EntityState
from hi.apps.model_helper import HiModelHelper
-from hi.integrations.integration_key import IntegrationKey
+from hi.integrations.transient_models import IntegrationKey
from .enums import HassStateValue
from .hass_metadata import HassMetaData
@@ -28,25 +29,74 @@ logger = logging.getLogger(__name__)
class HassConverter:
"""
- - Converts HAss API states into devices.
- - HAss devices might consist of multiple states.
- - A HAss device is the equivalent of an HI Entity.
- - Determines which HAss devices will be imported into HI.
- - The HAss API reponse does not make the the state to device relationship explicit.
+ Converts Home Assistant API states into HI devices with comprehensive service call support.
+
+ OVERVIEW:
+ - Converts HA API states into HI devices (Entity models)
+ - HA devices may consist of multiple states (e.g., light.kitchen + switch.kitchen = one device)
+ - Determines which HA devices are imported into HI
+ - HA API response doesn't make state-to-device relationships explicit, so we use heuristics
+
+ ARCHITECTURE:
+
+ 1. DEVICE AGGREGATION (heuristic grouping of HassStates into HassDevices):
+ - device_group_id: States with same Insteon address are grouped together
+ - full_name matching: States with same name but different domains are grouped
+ - suffix-based logic: Removes known suffixes (_temperature, _battery) to find base device
+ - switch/light deduplication: Avoids creating duplicate entities for dual-domain devices
+
+ 2. ENTITY-STATE MAPPING (structured mapping from HA domains/device_classes to EntityStateTypes):
+ - Uses HASS_STATE_TO_ENTITY_STATE_TYPE_MAPPING table for consistent, predictable mapping
+ - Key: (domain, device_class, has_brightness) → EntityStateType
+ - Handles special cases: dimmer lights, door sensors, temperature sensors, etc.
+ - Replaces old heuristic if/else chains with maintainable lookup tables
+
+ 3. CONTROLLABILITY DETERMINATION:
+ - ON_OFF_CONTROLLABLE_DOMAINS: light, switch (simple on/off control)
+ - COMPLEX_CONTROLLABLE_DOMAINS: cover, fan, climate, etc. (multiple services)
+ - SENSOR_ONLY_DOMAINS: binary_sensor, sensor, camera (read-only)
+ - Uses _is_controllable_domain_and_type() for precise control determination
+
+ 4. SERVICE CALL PAYLOAD (storage of service routing info for device control):
+ - CONTROL_SERVICE_MAPPING: (domain, EntityStateType) → service names and parameters
+ - Payload data stored during import contains: domain, on_service, off_service, capabilities
+ - Controller uses payload data directly without runtime lookups or EntityStateType awareness
+ - Enables proper HA service calls (turn_on/turn_off) instead of unreliable set_state API
+
+ 5. CONTROLLER + SENSOR CREATION:
+ - Controllable devices: Create Controller (which auto-creates associated Sensor)
+ - Sensor-only devices: Create Sensor only
+ - All models store integration payload data for service call routing
+ - Maintains 1:1 HassState ↔ EntityState mapping with proper separation of concerns
+
+ RATIONALE:
+ - Centralizes all HA integration complexity in converter (import-time)
+ - Controller becomes simple payload consumer (runtime)
+ - Service calls work reliably vs set_state which only updates HA internal state
+ - Structured mappings are maintainable vs scattered heuristic logic
+ - Backward compatible with existing device grouping and alarm event creation
+
+ FLOW:
+ HA API → HassStates → Device Grouping → EntityState Mapping → Service Payload →
+ Controller/Sensor Creation → Payload Storage → Runtime Service Calls
"""
- # Ignore all states that have these prefixes.
+ # Ignore all states from these domains - typically non-physical entities
+ # that don't represent controllable devices or useful sensors
#
- IGNORE_PREFIXES = {
- HassApi.AUTOMATION_ID_PREFIX,
- HassApi.CALENDAR_ID_PREFIX,
- HassApi.CONVERSATION_ID_PREFIX,
- HassApi.PERSON_ID_PREFIX,
- HassApi.SCRIPT_ID_PREFIX,
- HassApi.TODO_ID_PREFIX,
- HassApi.TTS_ID_PREFIX,
- HassApi.ZONE_ID_PREFIX,
+ IGNORE_DOMAINS = {
+ HassApi.AUTOMATION_DOMAIN,
+ HassApi.CALENDAR_DOMAIN,
+ HassApi.CONVERSATION_DOMAIN,
+ HassApi.PERSON_DOMAIN,
+ HassApi.SCRIPT_DOMAIN,
+ HassApi.TODO_DOMAIN,
+ HassApi.TTS_DOMAIN,
+ HassApi.ZONE_DOMAIN,
}
+
+ # Legacy alias for backward compatibility (remove after migration)
+ IGNORE_PREFIXES = IGNORE_DOMAINS
# Suffixes that suggest the HAss state may be part of another device
# and the "name" of the device precedes the suffix.
@@ -74,27 +124,177 @@ class HassConverter:
HassApi.BLACK_CARTRIDGE_ID_SUFFIX,
}
- # HAss entity id prefixes that define an two-value (on-off) switch
+ # Domains for controllable devices that support on/off operations
#
- SWITCH_PREFIXES = {
- HassApi.SWITCH_ID_PREFIX,
- HassApi.LIGHT_ID_PREFIX,
+ ON_OFF_CONTROLLABLE_DOMAINS = {
+ HassApi.SWITCH_DOMAIN,
+ HassApi.LIGHT_DOMAIN,
}
- SENSOR_PREFIXES = {
- HassApi.BINARY_SENSOR_ID_PREFIX,
- HassApi.SENSOR_ID_PREFIX,
+
+ # Domains for controllable devices that support more complex operations
+ #
+ COMPLEX_CONTROLLABLE_DOMAINS = {
+ HassApi.COVER_DOMAIN, # open, close, set_position
+ HassApi.FAN_DOMAIN, # turn_on, turn_off, set_speed
+ HassApi.CLIMATE_DOMAIN, # set_temperature, set_hvac_mode
+ HassApi.LOCK_DOMAIN, # lock, unlock
+ HassApi.MEDIA_PLAYER_DOMAIN, # play, pause, volume_set
+ }
+
+ # All controllable domains
+ ALL_CONTROLLABLE_DOMAINS = ON_OFF_CONTROLLABLE_DOMAINS | COMPLEX_CONTROLLABLE_DOMAINS
+
+ # Domains for sensor-only devices (read-only)
+ #
+ SENSOR_ONLY_DOMAINS = {
+ HassApi.BINARY_SENSOR_DOMAIN,
+ HassApi.SENSOR_DOMAIN,
+ HassApi.CAMERA_DOMAIN,
+ HassApi.SUN_DOMAIN,
+ HassApi.WEATHER_DOMAIN,
}
- PREFERRED_NAME_PREFIXES = {
- HassApi.CAMERA_ID_PREFIX,
- HassApi.CLIMATE_ID_PREFIX,
- HassApi.LIGHT_ID_PREFIX,
- HassApi.SUN_ID_PREFIX,
+ # Domains that should be preferred when choosing friendly names for devices
+ #
+ PREFERRED_NAME_DOMAINS = {
+ HassApi.CAMERA_DOMAIN,
+ HassApi.CLIMATE_DOMAIN,
+ HassApi.LIGHT_DOMAIN,
+ HassApi.SUN_DOMAIN,
}
+
PREFERRED_NAME_DEVICE_CLASSES = {
HassApi.MOTION_DEVICE_CLASS,
}
+ # Mapping 1: Import Mapping - determines EntityStateType during import
+ # Key: (domain, device_class_or_None, has_brightness_or_None)
+ # Value: EntityStateType
+ #
+ HASS_STATE_TO_ENTITY_STATE_TYPE_MAPPING = {
+
+ # Light Domain
+ (HassApi.LIGHT_DOMAIN, None, True): EntityStateType.LIGHT_DIMMER,
+ (HassApi.LIGHT_DOMAIN, None, False): EntityStateType.ON_OFF,
+ (HassApi.LIGHT_DOMAIN, None, None): EntityStateType.ON_OFF, # Default when brightness unknown
+
+ # Switch Domain
+ (HassApi.SWITCH_DOMAIN, None, None): EntityStateType.ON_OFF,
+
+ # Cover Domain (blinds, curtains, garage doors)
+ (HassApi.COVER_DOMAIN, HassApi.DOOR_DEVICE_CLASS, None): EntityStateType.OPEN_CLOSE,
+ (HassApi.COVER_DOMAIN, HassApi.GARAGE_DOOR_DEVICE_CLASS, None): EntityStateType.OPEN_CLOSE,
+ (HassApi.COVER_DOMAIN, HassApi.WINDOW_DEVICE_CLASS, None): EntityStateType.OPEN_CLOSE,
+ (HassApi.COVER_DOMAIN, None, None): EntityStateType.OPEN_CLOSE, # Default for covers
+
+ # Fan Domain
+ (HassApi.FAN_DOMAIN, None, None): EntityStateType.ON_OFF,
+
+ # Climate Domain
+ (HassApi.CLIMATE_DOMAIN, None, None): EntityStateType.TEMPERATURE,
+
+ # Lock Domain
+ (HassApi.LOCK_DOMAIN, None, None): EntityStateType.ON_OFF, # on=locked, off=unlocked
+
+ # Media Player Domain
+ (HassApi.MEDIA_PLAYER_DOMAIN, None, None): EntityStateType.ON_OFF,
+
+ # Binary Sensor Domain (read-only sensors)
+ (HassApi.BINARY_SENSOR_DOMAIN, HassApi.MOTION_DEVICE_CLASS, None): EntityStateType.MOVEMENT,
+ (HassApi.BINARY_SENSOR_DOMAIN, HassApi.CONNECTIVITY_DEVICE_CLASS, None): EntityStateType.CONNECTIVITY,
+ (HassApi.BINARY_SENSOR_DOMAIN, HassApi.BATTERY_DEVICE_CLASS, None): EntityStateType.HIGH_LOW,
+ (HassApi.BINARY_SENSOR_DOMAIN, HassApi.DOOR_DEVICE_CLASS, None): EntityStateType.OPEN_CLOSE,
+ (HassApi.BINARY_SENSOR_DOMAIN, HassApi.GARAGE_DOOR_DEVICE_CLASS, None): EntityStateType.OPEN_CLOSE,
+ (HassApi.BINARY_SENSOR_DOMAIN, HassApi.WINDOW_DEVICE_CLASS, None): EntityStateType.OPEN_CLOSE,
+ (HassApi.BINARY_SENSOR_DOMAIN, None, None): EntityStateType.ON_OFF, # Generic binary sensor
+
+ # Sensor Domain (read-only sensors)
+ (HassApi.SENSOR_DOMAIN, HassApi.TEMPERATURE_DEVICE_CLASS, None): EntityStateType.TEMPERATURE,
+ (HassApi.SENSOR_DOMAIN, HassApi.HUMIDITY_DEVICE_CLASS, None): EntityStateType.HUMIDITY,
+ (HassApi.SENSOR_DOMAIN, HassApi.TIMESTAMP_DEVICE_CLASS, None): EntityStateType.DATETIME,
+ (HassApi.SENSOR_DOMAIN, HassApi.ENUM_DEVICE_CLASS, None): EntityStateType.DISCRETE,
+ (HassApi.SENSOR_DOMAIN, None, None): EntityStateType.BLOB, # Generic sensor
+
+ # Other domains (read-only)
+ (HassApi.CAMERA_DOMAIN, None, None): EntityStateType.VIDEO_STREAM,
+ (HassApi.SUN_DOMAIN, None, None): EntityStateType.MULTVALUED,
+ (HassApi.WEATHER_DOMAIN, None, None): EntityStateType.MULTVALUED,
+ }
+
+ # Mapping 2: Control Service Mapping - only for controllable EntityStates
+ # Key: (domain, EntityStateType)
+ # Value: dict with service names and parameter mappings
+ #
+ CONTROL_SERVICE_MAPPING = {
+
+ # Light Domain Services
+ (HassApi.LIGHT_DOMAIN, EntityStateType.ON_OFF): {
+ 'on_service': HassApi.TURN_ON_SERVICE,
+ 'off_service': HassApi.TURN_OFF_SERVICE,
+ 'parameters': {},
+ },
+ (HassApi.LIGHT_DOMAIN, EntityStateType.LIGHT_DIMMER): {
+ 'on_service': HassApi.TURN_ON_SERVICE,
+ 'off_service': HassApi.TURN_OFF_SERVICE,
+ 'set_service': HassApi.TURN_ON_SERVICE, # For brightness setting
+ 'parameters': {
+ 'brightness_pct': 'percentage', # 0-100
+ },
+ },
+
+ # Switch Domain Services
+ (HassApi.SWITCH_DOMAIN, EntityStateType.ON_OFF): {
+ 'on_service': HassApi.TURN_ON_SERVICE,
+ 'off_service': HassApi.TURN_OFF_SERVICE,
+ 'parameters': {},
+ },
+
+ # Cover Domain Services
+ (HassApi.COVER_DOMAIN, EntityStateType.OPEN_CLOSE): {
+ 'on_service': HassApi.OPEN_COVER_SERVICE, # 'on' = open
+ 'off_service': HassApi.CLOSE_COVER_SERVICE, # 'off' = close
+ 'set_service': HassApi.SET_COVER_POSITION_SERVICE,
+ 'parameters': {
+ 'position': 'percentage', # 0-100
+ },
+ },
+
+ # Fan Domain Services
+ (HassApi.FAN_DOMAIN, EntityStateType.ON_OFF): {
+ 'on_service': HassApi.TURN_ON_SERVICE,
+ 'off_service': HassApi.TURN_OFF_SERVICE,
+ 'set_service': HassApi.SET_PERCENTAGE_SERVICE,
+ 'parameters': {
+ 'percentage': 'percentage', # 0-100
+ },
+ },
+
+ # Climate Domain Services
+ (HassApi.CLIMATE_DOMAIN, EntityStateType.TEMPERATURE): {
+ 'set_service': HassApi.SET_TEMPERATURE_SERVICE,
+ 'parameters': {
+ 'temperature': 'temperature', # Numeric temperature value
+ },
+ },
+
+ # Lock Domain Services
+ (HassApi.LOCK_DOMAIN, EntityStateType.ON_OFF): {
+ 'on_service': HassApi.LOCK_SERVICE, # 'on' = locked
+ 'off_service': HassApi.UNLOCK_SERVICE, # 'off' = unlocked
+ 'parameters': {},
+ },
+
+ # Media Player Domain Services
+ (HassApi.MEDIA_PLAYER_DOMAIN, EntityStateType.ON_OFF): {
+ 'on_service': HassApi.TURN_ON_SERVICE,
+ 'off_service': HassApi.TURN_OFF_SERVICE,
+ 'set_service': HassApi.VOLUME_SET_SERVICE,
+ 'parameters': {
+ 'volume_level': 'percentage_decimal', # 0.0-1.0
+ },
+ },
+ }
+
INSTEON_ADDRESS_ATTR_NAME = 'Insteon Address'
@classmethod
@@ -102,15 +302,17 @@ class HassConverter:
entity_id = api_dict.get( HassApi.ENTITY_ID_FIELD )
- # Since a device/entity can have multiple HAss states, and since the API does not
+ # Parse domain from entity_id (e.g., 'light' from 'light.living_room_lamp')
m = re.search( r'^([^\.]+)\.(.+)$', entity_id )
if m:
- prefix = m.group(1)
+ domain = m.group(1)
full_name = m.group(2)
else:
- prefix = entity_id
+ # Fallback for malformed entity_ids
+ domain = entity_id
full_name = entity_id
+ # Remove known suffixes to get device name
name = full_name
for suffix in cls.STATE_SUFFIXES:
if not full_name.endswith( suffix ):
@@ -121,7 +323,7 @@ class HassConverter:
return HassState(
api_dict = api_dict,
entity_id = entity_id,
- entity_id_prefix = prefix,
+ domain = domain,
entity_name_sans_prefix = full_name,
entity_name_sans_suffix = name,
)
@@ -142,41 +344,41 @@ class HassConverter:
##########
# First pass to gather candidate device names.
- # All names (ignoring prefix) seen with a known suffix. Values are set of prefixes seen.
+ # All names (ignoring domain) seen with a known suffix. Values are set of domains seen.
names_seen_with_suffixes = dict()
- # All full names seen (ignoring suffix). Values are set of prefixes seen.
- full_names_without_prefix = dict()
+ # All full names seen (ignoring suffix). Values are set of domains seen.
+ full_names_without_domain = dict()
- # Special group names when there are othere attributes that
+ # Special group names when there are other attributes that
# uniquely identify a device.
#
group_ids = dict()
for hass_state in hass_entity_id_to_state.values():
- prefix = hass_state.entity_id_prefix
+ domain = hass_state.domain
full_name = hass_state.entity_name_sans_prefix
short_name = hass_state.entity_name_sans_suffix
- if prefix in cls.IGNORE_PREFIXES:
+ if domain in cls.IGNORE_DOMAINS:
continue
# All states with same insteon address are from same device
if hass_state.device_group_id:
if hass_state.device_group_id not in group_ids:
group_ids[hass_state.device_group_id] = set()
- group_ids[hass_state.device_group_id].add( prefix )
+ group_ids[hass_state.device_group_id].add( domain )
- if full_name not in full_names_without_prefix:
- full_names_without_prefix[full_name] = set()
- full_names_without_prefix[full_name].add( prefix )
+ if full_name not in full_names_without_domain:
+ full_names_without_domain[full_name] = set()
+ full_names_without_domain[full_name].add( domain )
if short_name == full_name:
continue
if short_name not in names_seen_with_suffixes:
names_seen_with_suffixes[short_name] = set()
- names_seen_with_suffixes[short_name].add( prefix )
+ names_seen_with_suffixes[short_name].add( domain )
continue
@@ -187,11 +389,11 @@ class HassConverter:
for hass_state in hass_entity_id_to_state.values():
- prefix = hass_state.entity_id_prefix
+ domain = hass_state.domain
full_name = hass_state.entity_name_sans_prefix
short_name = hass_state.entity_name_sans_suffix
- if prefix in cls.IGNORE_PREFIXES:
+ if domain in cls.IGNORE_DOMAINS:
continue
# Simplest case of having explicit group id
@@ -200,7 +402,7 @@ class HassConverter:
hass_device.add_state( hass_state = hass_state )
continue
- # Next case of joining states is when only the prefix is different.
+ # Next case of joining states is when only the domain is different.
if full_name in hass_device_id_to_device:
hass_device = hass_device_id_to_device[full_name]
hass_device.add_state( hass_state = hass_state )
@@ -337,7 +539,24 @@ class HassConverter:
sensor = entiity_sensors.get( state_integration_key )
controller = entiity_controllers.get( state_integration_key )
- if not sensor and not controller:
+ # Update integration payload for existing sensors and controllers
+ # Every HassState should have at least a sensor, potentially also a controller
+ if sensor or controller:
+ # Use sensor or controller to determine EntityStateType (they should be the same)
+ model_with_entity_state = controller if controller else sensor
+ existing_entity_state_type = model_with_entity_state.entity_state.entity_state_type
+ is_controllable = cls._is_controllable_domain_and_type(hass_state.domain, existing_entity_state_type)
+
+ # Generate new payload using existing logic
+ new_payload = cls._create_service_payload(hass_state, existing_entity_state_type, is_controllable)
+
+ # Update payload for both sensor and controller if they exist
+ for model, model_type in [(sensor, 'sensor'), (controller, 'controller')]:
+ if model:
+ changed_fields = model.update_integration_payload(new_payload)
+ if changed_fields:
+ messages.append(f'Updated payload for {model_type} {model}: {", ".join(changed_fields)}')
+ else:
messages.append( f'Missing sensors/controllers for {entity}. Adding {hass_state}' )
new_hass_state_list.append( hass_state )
@@ -400,23 +619,23 @@ class HassConverter:
for hass_state in hass_state_list:
- if (( hass_state.entity_id_prefix == HassApi.SWITCH_ID_PREFIX )
- and ( HassApi.LIGHT_ID_PREFIX in prefixes_seen )):
- ignore_light_state_prefixes.add( hass_state.entity_id_prefix )
+ if (( hass_state.domain == HassApi.SWITCH_DOMAIN )
+ and ( HassApi.LIGHT_DOMAIN in prefixes_seen )):
+ ignore_light_state_prefixes.add( hass_state.domain )
- elif (( hass_state.entity_id_prefix == HassApi.LIGHT_ID_PREFIX )
- and ( HassApi.SWITCH_ID_PREFIX in prefixes_seen )):
- ignore_light_state_prefixes.add( hass_state.entity_id_prefix )
+ elif (( hass_state.domain == HassApi.LIGHT_DOMAIN )
+ and ( HassApi.SWITCH_DOMAIN in prefixes_seen )):
+ ignore_light_state_prefixes.add( hass_state.domain )
- prefixes_seen.add( hass_state.entity_id_prefix )
+ prefixes_seen.add( hass_state.domain )
continue
prefix_to_entity_state = dict()
for hass_state in hass_state_list:
state_integration_key = cls.hass_state_to_integration_key( hass_state = hass_state )
- if (( hass_state.entity_id_prefix == HassApi.LIGHT_ID_PREFIX )
- and ( hass_state.entity_id_prefix in ignore_light_state_prefixes )):
+ if (( hass_state.domain == HassApi.LIGHT_DOMAIN )
+ and ( hass_state.domain in ignore_light_state_prefixes )):
continue
entity_state = cls._create_hass_state_sensor_or_controller(
@@ -426,7 +645,7 @@ class HassConverter:
integration_key = state_integration_key,
add_alarm_events = add_alarm_events,
)
- prefix_to_entity_state[hass_state.entity_id_prefix] = entity_state
+ prefix_to_entity_state[hass_state.domain] = entity_state
continue
return
@@ -438,69 +657,273 @@ class HassConverter:
integration_key : IntegrationKey,
add_alarm_events : bool ) -> EntityState:
name = hass_state.friendly_name
- device_class = hass_state.device_class
if not name:
- name = f'{entity.name} ({hass_state.entity_id_prefix})'
+ name = f'{entity.name} ({hass_state.domain})'
+
+ # Use new mapping logic to determine EntityStateType and controllability
+ entity_state_type = cls._determine_entity_state_type_from_mapping( hass_state )
+ is_controllable = cls._is_controllable_domain_and_type( hass_state.domain, entity_state_type )
+
+ # Create domain payload for service calls - store service routing info directly
+ domain_payload = cls._create_service_payload( hass_state, entity_state_type, is_controllable )
##########
- # Controllers - Only for states we explicitly know are controllable.
+ # Controllers - Create controller (which also creates sensor) for controllable states
- if hass_state.entity_id_prefix in cls.SWITCH_PREFIXES:
- controller = HiModelHelper.create_on_off_controller(
- entity = entity,
- integration_key = integration_key,
- name = name,
+ if is_controllable:
+ controller = cls._create_controller_from_entity_state_type(
+ entity_state_type, entity, integration_key, name, domain_payload
)
return controller.entity_state
##########
- # Sensors - All HAss states are at least a sensor except for those
- # we know are controllable.
+ # Sensors - Create sensor-only for non-controllable states using mapping logic
+
+ sensor = cls._create_sensor_from_entity_state_type_with_params(
+ entity_state_type, entity, integration_key, name, domain_payload,
+ hass_state, add_alarm_events
+ )
+ return sensor.entity_state
- if hass_state.entity_id_prefix == HassApi.SUN_ID_PREFIX:
- sensor = HiModelHelper.create_multivalued_sensor(
+ @classmethod
+ def _create_hass_state_with_mapping( cls,
+ hass_device : HassDevice,
+ hass_state : HassState,
+ entity : Entity,
+ integration_key : IntegrationKey,
+ add_alarm_events : bool ) -> EntityState:
+ """
+ New method using mapping tables to determine EntityStateType and create
+ appropriate sensor or controller with domain payload storage.
+ """
+
+ # Step 1: Determine EntityStateType using our mapping table
+ entity_state_type = cls._determine_entity_state_type_from_mapping( hass_state )
+
+ # Step 2: Create domain payload to store for future service calls
+ domain_payload = {
+ 'domain': hass_state.domain,
+ 'device_class': hass_state.device_class,
+ 'has_brightness': cls._has_brightness_capability( hass_state ),
+ }
+
+ # Step 3: Create IntegrationKey (payload will be stored separately)
+ integration_key_for_storage = integration_key
+
+ # Step 4: Determine if this should be a controller or sensor
+ is_controllable = cls._is_controllable_domain_and_type( hass_state.domain, entity_state_type )
+
+ # Step 5: Create appropriate model (controller or sensor)
+ name = hass_state.friendly_name or f'{entity.name} ({hass_state.domain})'
+
+ if is_controllable:
+ # Create controller and store payload
+ entity_state = cls._create_controller_from_entity_state_type(
+ entity_state_type, entity, integration_key_for_storage, name, domain_payload
+ )
+ else:
+ # Create sensor and store payload
+ entity_state = cls._create_sensor_from_entity_state_type(
+ entity_state_type, entity, integration_key_for_storage, name, domain_payload
+ )
+
+ return entity_state
+
+ @classmethod
+ def _determine_entity_state_type_from_mapping( cls, hass_state: HassState ) -> EntityStateType:
+ """Use mapping table to determine EntityStateType from HassState"""
+
+ domain = hass_state.domain
+ device_class = hass_state.device_class
+ has_brightness = cls._has_brightness_capability( hass_state )
+
+ # Try exact match first
+ mapping_key = (domain, device_class, has_brightness)
+ if mapping_key in cls.HASS_STATE_TO_ENTITY_STATE_TYPE_MAPPING:
+ return cls.HASS_STATE_TO_ENTITY_STATE_TYPE_MAPPING[mapping_key]
+
+ # Try with None device_class
+ mapping_key = (domain, None, has_brightness)
+ if mapping_key in cls.HASS_STATE_TO_ENTITY_STATE_TYPE_MAPPING:
+ return cls.HASS_STATE_TO_ENTITY_STATE_TYPE_MAPPING[mapping_key]
+
+ # Try with None brightness
+ mapping_key = (domain, device_class, None)
+ if mapping_key in cls.HASS_STATE_TO_ENTITY_STATE_TYPE_MAPPING:
+ return cls.HASS_STATE_TO_ENTITY_STATE_TYPE_MAPPING[mapping_key]
+
+ # Try with both None
+ mapping_key = (domain, None, None)
+ if mapping_key in cls.HASS_STATE_TO_ENTITY_STATE_TYPE_MAPPING:
+ return cls.HASS_STATE_TO_ENTITY_STATE_TYPE_MAPPING[mapping_key]
+
+ # Fallback for unmapped domains
+ logger.warning( f'No mapping found for domain {domain}, device_class {device_class}. Using BLOB.' )
+ return EntityStateType.BLOB
+
+ @classmethod
+ def _has_brightness_capability( cls, hass_state: HassState ) -> bool:
+ """Check if a light has brightness/dimming capability"""
+ if hass_state.domain != HassApi.LIGHT_DOMAIN:
+ return False
+
+ # Check if brightness is in the state attributes
+ attributes = hass_state.attributes
+ return 'brightness' in attributes or 'brightness_pct' in attributes
+
+ @classmethod
+ def _is_controllable_domain_and_type( cls, domain: str, entity_state_type: EntityStateType ) -> bool:
+ """Check if this domain+type combination is controllable"""
+ return (domain, entity_state_type) in cls.CONTROL_SERVICE_MAPPING
+
+ @classmethod
+ def _create_controller_from_entity_state_type( cls,
+ entity_state_type : EntityStateType,
+ entity : Entity,
+ integration_key : IntegrationKey,
+ name : str,
+ domain_payload : dict ):
+ """Create appropriate controller based on EntityStateType"""
+
+ if entity_state_type == EntityStateType.ON_OFF:
+ controller = HiModelHelper.create_on_off_controller(
entity = entity,
integration_key = integration_key,
name = name,
)
- return sensor.entity_state
-
- if hass_state.entity_id_prefix == HassApi.WEATHER_ID_PREFIX:
+ elif entity_state_type == EntityStateType.LIGHT_DIMMER:
+ controller = HiModelHelper.create_light_dimmer_controller(
+ entity = entity,
+ integration_key = integration_key,
+ name = name,
+ )
+ elif entity_state_type == EntityStateType.OPEN_CLOSE:
+ controller = HiModelHelper.create_open_close_controller(
+ entity = entity,
+ integration_key = integration_key,
+ name = name,
+ )
+ elif entity_state_type == EntityStateType.TEMPERATURE:
+ controller = HiModelHelper.create_temperature_controller(
+ entity = entity,
+ integration_key = integration_key,
+ name = name,
+ )
+ else:
+ # Fallback - shouldn't happen for controllable types
+ logger.warning( f'Unknown controllable EntityStateType: {entity_state_type}' )
+ controller = HiModelHelper.create_on_off_controller(
+ entity = entity,
+ integration_key = integration_key,
+ name = name,
+ )
+
+ # Store domain payload
+ controller.integration_payload = domain_payload
+ controller.save()
+ return controller.entity_state
+
+ @classmethod
+ def _create_sensor_from_entity_state_type( cls,
+ entity_state_type : EntityStateType,
+ entity : Entity,
+ integration_key : IntegrationKey,
+ name : str,
+ domain_payload : dict ):
+ """Create appropriate sensor based on EntityStateType"""
+
+ if entity_state_type == EntityStateType.MOVEMENT:
+ sensor = HiModelHelper.create_movement_sensor(
+ entity = entity,
+ integration_key = integration_key,
+ name = name,
+ )
+ elif entity_state_type == EntityStateType.TEMPERATURE:
+ sensor = HiModelHelper.create_temperature_sensor(
+ entity = entity,
+ integration_key = integration_key,
+ name = name,
+ )
+ elif entity_state_type == EntityStateType.HUMIDITY:
+ sensor = HiModelHelper.create_humidity_sensor(
+ entity = entity,
+ integration_key = integration_key,
+ name = name,
+ )
+ elif entity_state_type == EntityStateType.MULTVALUED:
sensor = HiModelHelper.create_multivalued_sensor(
entity = entity,
integration_key = integration_key,
name = name,
)
- return sensor.entity_state
-
- if hass_state.entity_id_prefix == HassApi.BINARY_SENSOR_ID_PREFIX:
- sensor = cls._create_hass_state_binary_sensor(
- hass_device = hass_device,
- hass_state = hass_state,
+ elif entity_state_type == EntityStateType.VIDEO_STREAM:
+ sensor = HiModelHelper.create_video_stream_sensor(
entity = entity,
integration_key = integration_key,
- add_alarm_events = add_alarm_events,
+ name = name,
)
- return
+ elif entity_state_type == EntityStateType.CONNECTIVITY:
+ sensor = HiModelHelper.create_connectivity_sensor(
+ entity = entity,
+ integration_key = integration_key,
+ name = name,
+ )
+ elif entity_state_type == EntityStateType.HIGH_LOW:
+ sensor = HiModelHelper.create_high_low_sensor(
+ entity = entity,
+ integration_key = integration_key,
+ name = name,
+ )
+ elif entity_state_type == EntityStateType.ON_OFF:
+ sensor = HiModelHelper.create_on_off_sensor(
+ entity = entity,
+ integration_key = integration_key,
+ name = name,
+ )
+ else:
+ # Default fallback
+ sensor = HiModelHelper.create_blob_sensor(
+ entity = entity,
+ integration_key = integration_key,
+ name = name,
+ )
+
+ # Store domain payload for sensors too
+ sensor.integration_payload = domain_payload
+ sensor.save()
+ return sensor.entity_state
+
+ @classmethod
+ def _create_sensor_from_entity_state_type_with_params( cls,
+ entity_state_type : EntityStateType,
+ entity : Entity,
+ integration_key : IntegrationKey,
+ name : str,
+ domain_payload : dict,
+ hass_state : HassState,
+ add_alarm_events : bool ):
+ """Create appropriate sensor with legacy parameter handling"""
- if device_class == HassApi.TEMPERATURE_DEVICE_CLASS:
- if 'c' in hass_state.unit_of_measurement.lower():
+ if entity_state_type == EntityStateType.TEMPERATURE:
+ # Handle temperature units from HA data
+ unit_str = hass_state.unit_of_measurement or ''
+ if 'c' in unit_str.lower():
temperature_unit = TemperatureUnit.CELSIUS
else:
temperature_unit = TemperatureUnit.FAHRENHEIT
-
+
sensor = HiModelHelper.create_temperature_sensor(
entity = entity,
integration_key = integration_key,
name = name,
temperature_unit = temperature_unit,
)
- return sensor.entity_state
-
- if device_class == HassApi.HUMIDITY_DEVICE_CLASS:
- if 'kg' in hass_state.unit_of_measurement.lower():
+ elif entity_state_type == EntityStateType.HUMIDITY:
+ # Handle humidity units from HA data
+ unit_str = hass_state.unit_of_measurement or ''
+ if 'kg' in unit_str.lower():
humidity_unit = HumidityUnit.GRAMS_PER_KILOGRAM
- elif 'g' in hass_state.unit_of_measurement.lower():
+ elif 'g' in unit_str.lower():
humidity_unit = HumidityUnit.GRAMS_PER_CUBIN_METER
else:
humidity_unit = HumidityUnit.PERCENT
@@ -511,47 +934,16 @@ class HassConverter:
name = name,
humidity_unit = humidity_unit,
)
- return sensor.entity_state
-
- if device_class == HassApi.TIMESTAMP_DEVICE_CLASS:
- sensor = HiModelHelper.create_datetime_sensor(
- entity = entity,
- integration_key = integration_key,
- name = name,
- )
- return sensor.entity_state
-
- if device_class == HassApi.ENUM_DEVICE_CLASS:
+ elif entity_state_type == EntityStateType.DISCRETE:
+ # Handle enum device class with options
+ name_label_dict = { x: x for x in hass_state.options } if hass_state.options else {}
sensor = HiModelHelper.create_discrete_sensor(
entity = entity,
- name_label_dict = { x: x for x in hass_state.options },
+ name_label_dict = name_label_dict,
integration_key = integration_key,
name = name,
)
- return sensor.entity_state
-
- sensor = HiModelHelper.create_blob_sensor(
- entity = entity,
- integration_key = integration_key,
- name = name,
- )
- return sensor.entity_state
-
- @classmethod
- def _create_hass_state_binary_sensor( cls,
- hass_device : HassDevice,
- hass_state : HassState,
- entity : Entity,
- integration_key : IntegrationKey,
- add_alarm_events : bool ):
- name = hass_state.friendly_name
- device_class = hass_state.device_class
- if not name and device_class:
- name = f'{entity.name} ({device_class})'
- elif not name:
- name = f'{entity.name} ({hass_state.entity_id_prefix})'
-
- if hass_state.device_class == HassApi.CONNECTIVITY_DEVICE_CLASS:
+ elif entity_state_type == EntityStateType.CONNECTIVITY:
sensor = HiModelHelper.create_connectivity_sensor(
entity = entity,
integration_key = integration_key,
@@ -563,7 +955,7 @@ class HassConverter:
entity_state = sensor.entity_state,
integration_key = integration_key,
)
- elif hass_state.device_class in HassApi.OPEN_CLOSE_DEVICE_CLASS_SET:
+ elif entity_state_type == EntityStateType.OPEN_CLOSE:
sensor = HiModelHelper.create_open_close_sensor(
entity = entity,
integration_key = integration_key,
@@ -575,7 +967,7 @@ class HassConverter:
entity_state = sensor.entity_state,
integration_key = integration_key,
)
- elif hass_state.device_class == HassApi.MOTION_DEVICE_CLASS:
+ elif entity_state_type == EntityStateType.MOVEMENT:
sensor = HiModelHelper.create_movement_sensor(
entity = entity,
integration_key = integration_key,
@@ -587,31 +979,84 @@ class HassConverter:
entity_state = sensor.entity_state,
integration_key = integration_key,
)
- elif hass_state.device_class == HassApi.LIGHT_DEVICE_CLASS:
- HiModelHelper.create_on_off_sensor(
- entity = entity,
- integration_key = integration_key,
- name = name,
- )
- elif hass_state.device_class == HassApi.BATTERY_DEVICE_CLASS:
+ elif entity_state_type == EntityStateType.HIGH_LOW:
sensor = HiModelHelper.create_high_low_sensor(
entity = entity,
integration_key = integration_key,
name = name,
)
- if add_alarm_events:
+ if add_alarm_events and hass_state.device_class == HassApi.BATTERY_DEVICE_CLASS:
HiModelHelper.create_battery_event_definition(
name = f'{sensor.name} Alarm',
entity_state = sensor.entity_state,
integration_key = integration_key,
)
+ elif entity_state_type == EntityStateType.DATETIME:
+ sensor = HiModelHelper.create_datetime_sensor(
+ entity = entity,
+ integration_key = integration_key,
+ name = name,
+ )
+ elif entity_state_type == EntityStateType.MULTVALUED:
+ sensor = HiModelHelper.create_multivalued_sensor(
+ entity = entity,
+ integration_key = integration_key,
+ name = name,
+ )
+ elif entity_state_type == EntityStateType.VIDEO_STREAM:
+ sensor = HiModelHelper.create_video_stream_sensor(
+ entity = entity,
+ integration_key = integration_key,
+ name = name,
+ )
+ elif entity_state_type == EntityStateType.ON_OFF:
+ sensor = HiModelHelper.create_on_off_sensor(
+ entity = entity,
+ integration_key = integration_key,
+ name = name,
+ )
else:
- HiModelHelper.create_on_off_sensor(
+ # Default fallback
+ sensor = HiModelHelper.create_blob_sensor(
entity = entity,
integration_key = integration_key,
name = name,
)
- return
+
+ # Store domain payload for sensors
+ sensor.integration_payload = domain_payload
+ sensor.save()
+ return sensor
+
+ @classmethod
+ def _create_service_payload( cls, hass_state: HassState, entity_state_type: EntityStateType, is_controllable: bool ) -> dict:
+ """Create payload with service routing information for controllers"""
+
+ # Base payload for all entities
+ payload = {
+ 'domain': hass_state.domain,
+ 'device_class': hass_state.device_class,
+ 'entity_state_type': str(entity_state_type),
+ 'is_controllable': is_controllable,
+ }
+
+ # Add service routing information for controllable entities
+ if is_controllable:
+ mapping_key = (hass_state.domain, entity_state_type)
+ if mapping_key in cls.CONTROL_SERVICE_MAPPING:
+ service_mapping = cls.CONTROL_SERVICE_MAPPING[mapping_key]
+ payload.update(service_mapping)
+
+ # Add special capabilities
+ if entity_state_type == EntityStateType.LIGHT_DIMMER:
+ payload['supports_brightness'] = True
+ has_brightness = cls._has_brightness_capability( hass_state )
+ payload['has_brightness'] = has_brightness
+ else:
+ payload['supports_brightness'] = False
+ payload['has_brightness'] = False
+
+ return payload
@classmethod
def hass_device_to_entity_name( cls, hass_device : HassDevice ) -> str:
@@ -622,7 +1067,7 @@ class HassConverter:
friendly_name = hass_state.friendly_name
if not friendly_name:
continue
- if hass_state.entity_id_prefix in cls.PREFERRED_NAME_PREFIXES:
+ if hass_state.domain in cls.PREFERRED_NAME_DOMAINS:
return friendly_name
if hass_state.device_class in cls.PREFERRED_NAME_DEVICE_CLASSES:
return friendly_name
@@ -638,21 +1083,21 @@ class HassConverter:
@classmethod
def hass_device_to_entity_type( cls, hass_device : HassDevice ) -> EntityType:
- prefix_set = hass_device.entity_id_prefix_set
+ domain_set = hass_device.domain_set
device_class_set = hass_device.device_class_set
- if HassApi.CAMERA_ID_PREFIX in prefix_set:
+ if HassApi.CAMERA_DOMAIN in domain_set:
return EntityType.CAMERA
- if HassApi.WEATHER_ID_PREFIX in prefix_set:
+ if HassApi.WEATHER_DOMAIN in domain_set:
return EntityType.WEATHER_STATION
if HassApi.TIMESTAMP_DEVICE_CLASS in device_class_set:
return EntityType.TIME_SOURCE
- if ( HassApi.BINARY_SENSOR_ID_PREFIX in prefix_set
+ if ( HassApi.BINARY_SENSOR_DOMAIN in domain_set
and device_class_set.intersection( HassApi.OPEN_CLOSE_DEVICE_CLASS_SET )):
return EntityType.OPEN_CLOSE_SENSOR
if HassApi.MOTION_DEVICE_CLASS in device_class_set:
return EntityType.MOTION_SENSOR
- if ( HassApi.LIGHT_ID_PREFIX in prefix_set
+ if ( HassApi.LIGHT_DOMAIN in domain_set
or HassApi.LIGHT_DEVICE_CLASS in device_class_set ):
return EntityType.LIGHT
if HassApi.OUTLET_DEVICE_CLASS in device_class_set:
@@ -689,13 +1134,13 @@ class HassConverter:
@classmethod
def hass_state_to_sensor_value_str( self, hass_state : HassState ) -> str:
- if hass_state.entity_id_prefix == HassApi.SUN_ID_PREFIX:
+ if hass_state.domain == HassApi.SUN_DOMAIN:
return hass_state.state_value
- elif hass_state.entity_id_prefix == HassApi.WEATHER_ID_PREFIX:
+ elif hass_state.domain == HassApi.WEATHER_DOMAIN:
return hass_state.state_value
- elif hass_state.entity_id_prefix == HassApi.BINARY_SENSOR_ID_PREFIX:
+ elif hass_state.domain == HassApi.BINARY_SENSOR_DOMAIN:
if hass_state.state_value.lower() == HassStateValue.ON:
if hass_state.device_class in HassApi.MOTION_DEVICE_CLASS:
diff --git a/src/hi/services/hass/hass_manager.py b/src/hi/services/hass/hass_manager.py
index 85bf9e9f..05adec7b 100644
--- a/src/hi/services/hass/hass_manager.py
+++ b/src/hi/services/hass/hass_manager.py
@@ -6,7 +6,7 @@ from hi.apps.common.singleton import Singleton
from hi.apps.common.utils import str_to_bool
from hi.integrations.exceptions import IntegrationAttributeError, IntegrationError
-from hi.integrations.integration_key import IntegrationKey
+from hi.integrations.transient_models import IntegrationKey
from hi.integrations.models import Integration, IntegrationAttribute
from .enums import HassAttributeType
diff --git a/src/hi/services/hass/hass_models.py b/src/hi/services/hass/hass_models.py
index 4a199d65..01904a65 100644
--- a/src/hi/services/hass/hass_models.py
+++ b/src/hi/services/hass/hass_models.py
@@ -9,22 +9,61 @@ class HassApi:
ENTITY_ID_FIELD = 'entity_id'
STATE_FIELD = 'state'
- AUTOMATION_ID_PREFIX = 'automation'
- BINARY_SENSOR_ID_PREFIX = 'binary_sensor'
- CALENDAR_ID_PREFIX = 'calendar'
- CAMERA_ID_PREFIX = 'camera'
- CLIMATE_ID_PREFIX = ''
- CONVERSATION_ID_PREFIX = 'conversation'
- LIGHT_ID_PREFIX = 'light'
- PERSON_ID_PREFIX = 'person'
- SCRIPT_ID_PREFIX = 'script'
- SENSOR_ID_PREFIX = 'sensor'
- SUN_ID_PREFIX = 'sun'
- SWITCH_ID_PREFIX = 'switch'
- TODO_ID_PREFIX = 'todo'
- TTS_ID_PREFIX = 'tts'
- WEATHER_ID_PREFIX = 'weather'
- ZONE_ID_PREFIX = 'zone'
+ # Home Assistant Domain Constants
+ AUTOMATION_DOMAIN = 'automation'
+ BINARY_SENSOR_DOMAIN = 'binary_sensor'
+ CALENDAR_DOMAIN = 'calendar'
+ CAMERA_DOMAIN = 'camera'
+ CLIMATE_DOMAIN = 'climate'
+ CONVERSATION_DOMAIN = 'conversation'
+ COVER_DOMAIN = 'cover'
+ FAN_DOMAIN = 'fan'
+ LIGHT_DOMAIN = 'light'
+ LOCK_DOMAIN = 'lock'
+ MEDIA_PLAYER_DOMAIN = 'media_player'
+ PERSON_DOMAIN = 'person'
+ SCRIPT_DOMAIN = 'script'
+ SENSOR_DOMAIN = 'sensor'
+ SUN_DOMAIN = 'sun'
+ SWITCH_DOMAIN = 'switch'
+ TODO_DOMAIN = 'todo'
+ TTS_DOMAIN = 'tts'
+ WEATHER_DOMAIN = 'weather'
+ ZONE_DOMAIN = 'zone'
+
+ # Home Assistant Service Name Constants
+ TURN_ON_SERVICE = 'turn_on'
+ TURN_OFF_SERVICE = 'turn_off'
+ OPEN_COVER_SERVICE = 'open_cover'
+ CLOSE_COVER_SERVICE = 'close_cover'
+ SET_COVER_POSITION_SERVICE = 'set_cover_position'
+ SET_TEMPERATURE_SERVICE = 'set_temperature'
+ SET_HVAC_MODE_SERVICE = 'set_hvac_mode'
+ LOCK_SERVICE = 'lock'
+ UNLOCK_SERVICE = 'unlock'
+ MEDIA_PLAY_SERVICE = 'media_play'
+ MEDIA_PAUSE_SERVICE = 'media_pause'
+ MEDIA_STOP_SERVICE = 'media_stop'
+ VOLUME_SET_SERVICE = 'volume_set'
+ SET_PERCENTAGE_SERVICE = 'set_percentage'
+
+ # Legacy aliases for backward compatibility (remove after migration)
+ AUTOMATION_ID_PREFIX = AUTOMATION_DOMAIN
+ BINARY_SENSOR_ID_PREFIX = BINARY_SENSOR_DOMAIN
+ CALENDAR_ID_PREFIX = CALENDAR_DOMAIN
+ CAMERA_ID_PREFIX = CAMERA_DOMAIN
+ CLIMATE_ID_PREFIX = CLIMATE_DOMAIN
+ CONVERSATION_ID_PREFIX = CONVERSATION_DOMAIN
+ LIGHT_ID_PREFIX = LIGHT_DOMAIN
+ PERSON_ID_PREFIX = PERSON_DOMAIN
+ SCRIPT_ID_PREFIX = SCRIPT_DOMAIN
+ SENSOR_ID_PREFIX = SENSOR_DOMAIN
+ SUN_ID_PREFIX = SUN_DOMAIN
+ SWITCH_ID_PREFIX = SWITCH_DOMAIN
+ TODO_ID_PREFIX = TODO_DOMAIN
+ TTS_ID_PREFIX = TTS_DOMAIN
+ WEATHER_ID_PREFIX = WEATHER_DOMAIN
+ ZONE_ID_PREFIX = ZONE_DOMAIN
BATTERY_ID_SUFFIX = '_battery'
EVENTS_last_HOUR_ID_SUFFIX = '_events_last_hour'
@@ -74,11 +113,16 @@ class HassState:
api_dict : Dict
entity_id : str
- entity_id_prefix : str
+ domain : str
entity_name_sans_prefix : str
entity_name_sans_suffix : str
ignore : bool = True
+ # Legacy property for backward compatibility (remove after migration)
+ @property
+ def entity_id_prefix(self) -> str:
+ return self.domain
+
def __str__(self):
return f'HassState: {self.entity_id}'
@@ -156,9 +200,14 @@ class HassDevice:
def device_class_set(self):
return { x.device_class for x in self._hass_state_list if x.device_class }
+ @property
+ def domain_set(self):
+ return { x.domain for x in self._hass_state_list }
+
+ # Legacy property for backward compatibility (remove after migration)
@property
def entity_id_prefix_set(self):
- return { x.entity_id_prefix for x in self._hass_state_list }
+ return self.domain_set
def to_dict(self):
return {
diff --git a/src/hi/services/hass/hass_sync.py b/src/hi/services/hass/hass_sync.py
index 229bf061..9f9f78f1 100644
--- a/src/hi/services/hass/hass_sync.py
+++ b/src/hi/services/hass/hass_sync.py
@@ -7,7 +7,7 @@ from hi.apps.common.database_lock import ExclusionLockContext
from hi.apps.common.processing_result import ProcessingResult
from hi.apps.entity.models import Entity
-from hi.integrations.integration_key import IntegrationKey
+from hi.integrations.transient_models import IntegrationKey
from .hass_converter import HassConverter
from .hass_models import HassDevice
@@ -63,7 +63,7 @@ class HassSynchronizer( HassMixin ):
HassConverter.hass_device_to_integration_key( hass_device ): hass_device
for hass_device in hass_device_id_to_device.values()
}
-
+
with transaction.atomic():
for integration_key, hass_device in integration_key_to_hass_device.items():
entity = integration_key_to_entity.get( integration_key )
diff --git a/src/hi/services/hass/tests/__init__.py b/src/hi/services/hass/tests/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/src/hi/services/hass/tests/data/hass-states.json b/src/hi/services/hass/tests/data/hass-states.json
new file mode 100644
index 00000000..609b91d5
--- /dev/null
+++ b/src/hi/services/hass/tests/data/hass-states.json
@@ -0,0 +1,2436 @@
+[
+ {
+ "attributes": {
+ "device_trackers": [],
+ "editable": true,
+ "entity_picture": "/api/image/serve/6e091524e540239d51f3a41b007989d5/512x512",
+ "friendly_name": "Cassandra",
+ "icon": "mdi:account-group",
+ "id": "cassandra",
+ "user_id": "f6707281e954491cbccb97307afa2c0e"
+ },
+ "context": {
+ "id": "01JDJQTJRVA2ZEVPT7QA10H85K",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "person.cassandra",
+ "last_changed": "2024-11-25T22:41:46.842744+00:00",
+ "last_reported": "2024-11-25T22:42:10.331715+00:00",
+ "last_updated": "2024-11-25T22:42:10.331715+00:00",
+ "state": "unknown"
+ },
+ {
+ "attributes": {
+ "editable": true,
+ "friendly_name": "Cassandra HQ",
+ "icon": "mdi:home",
+ "latitude": 30.430472,
+ "longitude": -97.80474843885351,
+ "passive": false,
+ "persons": [],
+ "radius": 21
+ },
+ "context": {
+ "id": "01JDJQT1VS8DPSJY6Z90EA52HQ",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "zone.home",
+ "last_changed": "2024-11-25T22:41:53.017376+00:00",
+ "last_reported": "2024-11-25T22:41:53.017376+00:00",
+ "last_updated": "2024-11-25T22:41:53.017376+00:00",
+ "state": "0"
+ },
+ {
+ "attributes": {
+ "current": 0,
+ "friendly_name": "Play Door Chime",
+ "icon": "mdi:bullhorn-outline",
+ "last_triggered": "2024-11-30T02:13:45.358983+00:00",
+ "mode": "single"
+ },
+ "context": {
+ "id": "01JDXDGW8DX5KKY59P5S91ZSE2",
+ "parent_id": "01JDXDGT9XD74EH88MHYKF88PG",
+ "user_id": null
+ },
+ "entity_id": "script.play_door_chime",
+ "last_changed": "2024-11-30T02:13:45.359458+00:00",
+ "last_reported": "2024-11-30T02:13:45.359458+00:00",
+ "last_updated": "2024-11-30T02:13:45.359458+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "access_token": "9886f62fe6e1e59fc8f9fc9b0afb942156ddf1b3aaf440c5d4fa9506f5656f01",
+ "entity_picture": "/api/camera_proxy/camera.highcamera?token=9886f62fe6e1e59fc8f9fc9b0afb942156ddf1b3aaf440c5d4fa9506f5656f01",
+ "friendly_name": "HighCamera",
+ "supported_features": 0
+ },
+ "context": {
+ "id": "01JE596742C62P6SKVN76P26HC",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "camera.highcamera",
+ "last_changed": "2024-12-01T18:01:48.880152+00:00",
+ "last_reported": "2024-12-03T03:31:57.186566+00:00",
+ "last_updated": "2024-12-03T03:31:57.186566+00:00",
+ "state": "idle"
+ },
+ {
+ "attributes": {
+ "access_token": "e8da62c3bad3831df2a33e8c84010fedc388bfcf04e35ccb6d404ab160c03fd",
+ "entity_picture": "/api/camera_proxy/camera.backcamera?token=e8da62c3bad3831df2a33e8c84010fedc388bfcf04e35ccb6d404ab160c03fd",
+ "friendly_name": "BackCamera",
+ "supported_features": 0
+ },
+ "context": {
+ "id": "01JE596742HNSTEGGTPTFV2THZ",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "camera.backcamera",
+ "last_changed": "2024-11-25T22:42:26.480827+00:00",
+ "last_reported": "2024-12-03T03:31:57.186805+00:00",
+ "last_updated": "2024-12-03T03:31:57.186805+00:00",
+ "state": "idle"
+ },
+ {
+ "attributes": {
+ "access_token": "20881b57735a0b64bb8cc3c2784c7ea39138f9233e9ac0280dc6cc345020e11f",
+ "entity_picture": "/api/camera_proxy/camera.frontcamera?token=20881b57735a0b64bb8cc3c2784c7ea39138f9233e9ac0280dc6cc345020e11f",
+ "friendly_name": "FrontCamera",
+ "supported_features": 0
+ },
+ "context": {
+ "id": "01JE596742Z5P5R88297RGJX8Y",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "camera.frontcamera",
+ "last_changed": "2024-11-30T02:14:13.263993+00:00",
+ "last_reported": "2024-12-03T03:31:57.186941+00:00",
+ "last_updated": "2024-12-03T03:31:57.186941+00:00",
+ "state": "idle"
+ },
+ {
+ "attributes": {
+ "access_token": "7b6ab8674bfa408884b674c666efb1969a8a3c2da51e36079f9a8244cdcc9e01",
+ "entity_picture": "/api/camera_proxy/camera.patiocamera?token=7b6ab8674bfa408884b674c666efb1969a8a3c2da51e36079f9a8244cdcc9e01",
+ "friendly_name": "PatioCamera",
+ "supported_features": 0
+ },
+ "context": {
+ "id": "01JE596743EAVGR4VE6PW6YZ7A",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "camera.patiocamera",
+ "last_changed": "2024-12-03T02:49:26.435307+00:00",
+ "last_reported": "2024-12-03T03:31:57.187153+00:00",
+ "last_updated": "2024-12-03T03:31:57.187153+00:00",
+ "state": "idle"
+ },
+ {
+ "attributes": {
+ "access_token": "ea48604138f62cb57a3e977eacf3fa7ab221718113510d592e9828606163c611",
+ "entity_picture": "/api/camera_proxy/camera.sidecamera?token=ea48604138f62cb57a3e977eacf3fa7ab221718113510d592e9828606163c611",
+ "friendly_name": "SideCamera",
+ "supported_features": 0
+ },
+ "context": {
+ "id": "01JE596743NQFZQF7JTCRVZ190",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "camera.sidecamera",
+ "last_changed": "2024-12-03T02:49:26.977233+00:00",
+ "last_reported": "2024-12-03T03:31:57.232103+00:00",
+ "last_updated": "2024-12-03T03:31:57.187377+00:00",
+ "state": "idle"
+ },
+ {
+ "attributes": {
+ "access_token": "e27bfa3f1a7d9c81aad4253b4a6f99940c168c06ed27bd0197c024180231dc5",
+ "entity_picture": "/api/camera_proxy/camera.drivecamera?token=e27bfa3f1a7d9c81aad4253b4a6f99940c168c06ed27bd0197c024180231dc5",
+ "friendly_name": "DriveCamera",
+ "supported_features": 0
+ },
+ "context": {
+ "id": "01JE596743E3A9QR4Z3M8HGHA4",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "camera.drivecamera",
+ "last_changed": "2024-12-03T02:49:27.498058+00:00",
+ "last_reported": "2024-12-03T03:31:57.764053+00:00",
+ "last_updated": "2024-12-03T03:31:57.187572+00:00",
+ "state": "idle"
+ },
+ {
+ "attributes": {
+ "access_token": "e432cd3b6bc74fa55af462c635203714e355f8f2de8e9c15a3912a3fdb6ee1a7",
+ "entity_picture": "/api/camera_proxy/camera.poolcamera?token=e432cd3b6bc74fa55af462c635203714e355f8f2de8e9c15a3912a3fdb6ee1a7",
+ "friendly_name": "PoolCamera",
+ "supported_features": 0
+ },
+ "context": {
+ "id": "01JE5967435MP6Y14WV0VP25C4",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "camera.poolcamera",
+ "last_changed": "2024-12-03T02:49:28.026092+00:00",
+ "last_reported": "2024-12-03T03:31:58.310776+00:00",
+ "last_updated": "2024-12-03T03:31:57.187760+00:00",
+ "state": "idle"
+ },
+ {
+ "attributes": {
+ "access_token": "1740793333aa83baf3a3a61432ebce8ef6da26cdb629951eb01776b81dba4431",
+ "entity_picture": "/api/camera_proxy/camera.carcamera?token=1740793333aa83baf3a3a61432ebce8ef6da26cdb629951eb01776b81dba4431",
+ "friendly_name": "CarCamera",
+ "supported_features": 0
+ },
+ "context": {
+ "id": "01JE596743TBXYWYS847A7R08Y",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "camera.carcamera",
+ "last_changed": "2024-12-03T02:50:28.926328+00:00",
+ "last_reported": "2024-12-03T03:31:58.857247+00:00",
+ "last_updated": "2024-12-03T03:31:57.187934+00:00",
+ "state": "idle"
+ },
+ {
+ "attributes": {
+ "access_token": "ccfb108bddd680b96786a638824a8e47a7aa7db86ca370be3ab28f99aa6d7db2",
+ "entity_picture": "/api/camera_proxy/camera.garagecamera?token=ccfb108bddd680b96786a638824a8e47a7aa7db86ca370be3ab28f99aa6d7db2",
+ "friendly_name": "GarageCamera",
+ "supported_features": 0
+ },
+ "context": {
+ "id": "01JE596744QRTSGGV6D093N5QP",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "camera.garagecamera",
+ "last_changed": "2024-12-03T02:50:29.525326+00:00",
+ "last_reported": "2024-12-03T03:31:59.414579+00:00",
+ "last_updated": "2024-12-03T03:31:57.188100+00:00",
+ "state": "idle"
+ },
+ {
+ "attributes": {
+ "friendly_name": "HighCamera Status"
+ },
+ "context": {
+ "id": "01JE56RAJ05MAY8ABEK5JG2Q5Z",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.highcamera_status",
+ "last_changed": "2024-12-03T02:49:24.800428+00:00",
+ "last_reported": "2024-12-03T02:49:24.800428+00:00",
+ "last_updated": "2024-12-03T02:49:24.800428+00:00",
+ "state": "Modect"
+ },
+ {
+ "attributes": {
+ "friendly_name": "HighCamera Events Last Hour",
+ "unit_of_measurement": "Events"
+ },
+ "context": {
+ "id": "01JE1SJG2FK24F83155FV384BM",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.highcamera_events_last_hour",
+ "last_changed": "2024-12-01T19:01:19.055164+00:00",
+ "last_reported": "2024-12-01T19:01:19.055164+00:00",
+ "last_updated": "2024-12-01T19:01:19.055164+00:00",
+ "state": "0"
+ },
+ {
+ "attributes": {
+ "friendly_name": "BackCamera Status"
+ },
+ "context": {
+ "id": "01JE56RB23WY44YFNE6KW6QQ7F",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.backcamera_status",
+ "last_changed": "2024-12-03T02:49:25.315314+00:00",
+ "last_reported": "2024-12-03T02:49:25.315314+00:00",
+ "last_updated": "2024-12-03T02:49:25.315314+00:00",
+ "state": "Modect"
+ },
+ {
+ "attributes": {
+ "friendly_name": "BackCamera Events Last Hour",
+ "unit_of_measurement": "Events"
+ },
+ "context": {
+ "id": "01JDJQV2GFBQ68SS510N67NFJY",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.backcamera_events_last_hour",
+ "last_changed": "2024-11-25T22:42:26.447471+00:00",
+ "last_reported": "2024-11-25T22:42:26.447471+00:00",
+ "last_updated": "2024-11-25T22:42:26.447471+00:00",
+ "state": "0"
+ },
+ {
+ "attributes": {
+ "friendly_name": "FrontCamera Status"
+ },
+ "context": {
+ "id": "01JE56RBJ85R96MK61SF0HCD65",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.frontcamera_status",
+ "last_changed": "2024-12-03T02:49:25.832891+00:00",
+ "last_reported": "2024-12-03T02:49:25.832891+00:00",
+ "last_updated": "2024-12-03T02:49:25.832891+00:00",
+ "state": "Modect"
+ },
+ {
+ "attributes": {
+ "friendly_name": "FrontCamera Events Last Hour",
+ "unit_of_measurement": "Events"
+ },
+ "context": {
+ "id": "01JE4Q76WCTGMGRZCTZ6SR570M",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.frontcamera_events_last_hour",
+ "last_changed": "2024-12-02T22:17:55.340858+00:00",
+ "last_reported": "2024-12-02T22:17:55.340858+00:00",
+ "last_updated": "2024-12-02T22:17:55.340858+00:00",
+ "state": "0"
+ },
+ {
+ "attributes": {
+ "friendly_name": "PatioCamera Status"
+ },
+ "context": {
+ "id": "01JE56RC28AD7T766HX3TJ9SZA",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.patiocamera_status",
+ "last_changed": "2024-12-03T02:49:26.344808+00:00",
+ "last_reported": "2024-12-03T02:49:26.344808+00:00",
+ "last_updated": "2024-12-03T02:49:26.344808+00:00",
+ "state": "Modect"
+ },
+ {
+ "attributes": {
+ "friendly_name": "PatioCamera Events Last Hour",
+ "unit_of_measurement": "Events"
+ },
+ "context": {
+ "id": "01JDJQV3N7TDPAXKMYKBAB4CNQ",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.patiocamera_events_last_hour",
+ "last_changed": "2024-11-25T22:42:27.623408+00:00",
+ "last_reported": "2024-11-25T22:42:27.623408+00:00",
+ "last_updated": "2024-11-25T22:42:27.623408+00:00",
+ "state": "0"
+ },
+ {
+ "attributes": {
+ "friendly_name": "SideCamera Status"
+ },
+ "context": {
+ "id": "01JE56RCHNNR0AQ8ZHF28HYM7E",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.sidecamera_status",
+ "last_changed": "2024-12-03T02:49:26.837249+00:00",
+ "last_reported": "2024-12-03T02:49:26.837249+00:00",
+ "last_updated": "2024-12-03T02:49:26.837249+00:00",
+ "state": "Modect"
+ },
+ {
+ "attributes": {
+ "friendly_name": "SideCamera Events Last Hour",
+ "unit_of_measurement": "Events"
+ },
+ "context": {
+ "id": "01JDJQV45FHH0PAWYMG80KNQVZ",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.sidecamera_events_last_hour",
+ "last_changed": "2024-11-25T22:42:28.143523+00:00",
+ "last_reported": "2024-11-25T22:42:28.143523+00:00",
+ "last_updated": "2024-11-25T22:42:28.143523+00:00",
+ "state": "0"
+ },
+ {
+ "attributes": {
+ "friendly_name": "DriveCamera Status"
+ },
+ "context": {
+ "id": "01JE56RD1VB7GQTC2YH45X47JR",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.drivecamera_status",
+ "last_changed": "2024-12-03T02:49:27.355107+00:00",
+ "last_reported": "2024-12-03T02:49:27.355107+00:00",
+ "last_updated": "2024-12-03T02:49:27.355107+00:00",
+ "state": "Modect"
+ },
+ {
+ "attributes": {
+ "friendly_name": "DriveCamera Events Last Hour",
+ "unit_of_measurement": "Events"
+ },
+ "context": {
+ "id": "01JE590R0SGVSVGS4EEJX34XES",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.drivecamera_events_last_hour",
+ "last_changed": "2024-12-03T03:28:57.881168+00:00",
+ "last_reported": "2024-12-03T03:28:57.881168+00:00",
+ "last_updated": "2024-12-03T03:28:57.881168+00:00",
+ "state": "0"
+ },
+ {
+ "attributes": {
+ "friendly_name": "PoolCamera Status"
+ },
+ "context": {
+ "id": "01JE56RDJFZH2YKWRC14KPFWED",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.poolcamera_status",
+ "last_changed": "2024-12-03T02:49:27.887676+00:00",
+ "last_reported": "2024-12-03T02:49:27.887676+00:00",
+ "last_updated": "2024-12-03T02:49:27.887676+00:00",
+ "state": "Modect"
+ },
+ {
+ "attributes": {
+ "friendly_name": "PoolCamera Events Last Hour",
+ "unit_of_measurement": "Events"
+ },
+ "context": {
+ "id": "01JDJQV58Z4AEQ7QNNN885ZQCN",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.poolcamera_events_last_hour",
+ "last_changed": "2024-11-25T22:42:29.279834+00:00",
+ "last_reported": "2024-11-25T22:42:29.279834+00:00",
+ "last_updated": "2024-11-25T22:42:29.279834+00:00",
+ "state": "0"
+ },
+ {
+ "attributes": {
+ "friendly_name": "CarCamera Status"
+ },
+ "context": {
+ "id": "01JE56T9411BBQ8JSCNMBKB625",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.carcamera_status",
+ "last_changed": "2024-12-03T02:50:28.865691+00:00",
+ "last_reported": "2024-12-03T02:50:28.865691+00:00",
+ "last_updated": "2024-12-03T02:50:28.865691+00:00",
+ "state": "Modect"
+ },
+ {
+ "attributes": {
+ "friendly_name": "CarCamera Events Last Hour",
+ "unit_of_measurement": "Events"
+ },
+ "context": {
+ "id": "01JE590S43AYCSVXSH3C97P0ZF",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.carcamera_events_last_hour",
+ "last_changed": "2024-12-03T03:28:59.011195+00:00",
+ "last_reported": "2024-12-03T03:28:59.011195+00:00",
+ "last_updated": "2024-12-03T03:28:59.011195+00:00",
+ "state": "0"
+ },
+ {
+ "attributes": {
+ "friendly_name": "GarageCamera Status"
+ },
+ "context": {
+ "id": "01JE56T9R7HYJEWG3PR98K3DX8",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.garagecamera_status",
+ "last_changed": "2024-12-03T02:50:29.511903+00:00",
+ "last_reported": "2024-12-03T02:50:29.511903+00:00",
+ "last_updated": "2024-12-03T02:50:29.511903+00:00",
+ "state": "Modect"
+ },
+ {
+ "attributes": {
+ "friendly_name": "GarageCamera Events Last Hour",
+ "unit_of_measurement": "Events"
+ },
+ "context": {
+ "id": "01JE599YJSJEW36EMRFF8BMG4Z",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.garagecamera_events_last_hour",
+ "last_changed": "2024-12-03T03:33:59.513894+00:00",
+ "last_reported": "2024-12-03T03:33:59.513894+00:00",
+ "last_updated": "2024-12-03T03:33:59.513894+00:00",
+ "state": "0"
+ },
+ {
+ "attributes": {
+ "friendly_name": "Run State"
+ },
+ "context": {
+ "id": "01JE56QH97ZFYAPYM7D34P1QT4",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.run_state",
+ "last_changed": "2024-12-03T02:48:58.919796+00:00",
+ "last_reported": "2024-12-03T02:48:58.919796+00:00",
+ "last_updated": "2024-12-03T02:48:58.919796+00:00",
+ "state": "Away"
+ },
+ {
+ "attributes": {
+ "friendly_name": "Home Assistant"
+ },
+ "context": {
+ "id": "01JDJQT41QXVRR2HMDT7889KDZ",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "conversation.home_assistant",
+ "last_changed": "2024-11-25T22:41:55.255485+00:00",
+ "last_reported": "2024-11-25T22:41:55.255485+00:00",
+ "last_updated": "2024-11-25T22:41:55.255485+00:00",
+ "state": "unknown"
+ },
+ {
+ "attributes": {
+ "color_mode": "onoff",
+ "friendly_name": "Kitchen Cooktop Light",
+ "supported_color_modes": [
+ "onoff"
+ ],
+ "supported_features": 0
+ },
+ "context": {
+ "id": "01JE4X5SVR69D47WR7VMKKJRG6",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "light.switchlinc_relay_18_36_41",
+ "last_changed": "2024-12-03T00:02:01.877409+00:00",
+ "last_reported": "2024-12-03T00:02:01.877409+00:00",
+ "last_updated": "2024-12-03T00:02:01.877409+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "color_mode": "onoff",
+ "friendly_name": "Deck Lights",
+ "supported_color_modes": [
+ "onoff"
+ ],
+ "supported_features": 0
+ },
+ "context": {
+ "id": "01JE4X5SVR69D47WR7VMKKJRG6",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "light.switchlinc_relay_dual_band_23_fa_31",
+ "last_changed": "2024-12-03T00:02:01.075887+00:00",
+ "last_reported": "2024-12-03T00:02:01.075887+00:00",
+ "last_updated": "2024-12-03T00:02:01.075887+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "color_mode": "onoff",
+ "friendly_name": "Kitchen Fridge Light",
+ "supported_color_modes": [
+ "onoff"
+ ],
+ "supported_features": 0
+ },
+ "context": {
+ "id": "01JE4X5V0NHR79CC315ZPH84SY",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "light.switchlinc_relay_18_36_41_2",
+ "last_changed": "2024-12-03T00:02:01.877574+00:00",
+ "last_reported": "2024-12-03T00:02:01.877574+00:00",
+ "last_updated": "2024-12-03T00:02:01.877574+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {},
+ "context": {
+ "id": "01JE58WCJVP4659S8SYW3HZPAY",
+ "parent_id": null,
+ "user_id": "f6707281e954491cbccb97307afa2c0e"
+ },
+ "entity_id": "light.switchlinc_relay_dual_band_43_54_48",
+ "last_changed": "2024-12-03T03:26:35.099256+00:00",
+ "last_reported": "2024-12-03T03:26:35.099256+00:00",
+ "last_updated": "2024-12-03T03:26:35.099256+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "color_mode": null,
+ "friendly_name": "Side Deck Light",
+ "supported_color_modes": [
+ "onoff"
+ ],
+ "supported_features": 0
+ },
+ "context": {
+ "id": "01JDJQTG1191V2R6544JS17VY5",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "light.switchlinc_relay_dual_band_23_ee_08",
+ "last_changed": "2024-11-25T22:42:07.521822+00:00",
+ "last_reported": "2024-11-25T22:42:07.521822+00:00",
+ "last_updated": "2024-11-25T22:42:07.521822+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "color_mode": null,
+ "friendly_name": "Fireplace Light",
+ "supported_color_modes": [
+ "onoff"
+ ],
+ "supported_features": 0
+ },
+ "context": {
+ "id": "01JE4T4QPQ3SC6TY0KFGWAKTRR",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "light.switchlinc_relay_18_36_cb",
+ "last_changed": "2024-12-02T23:08:59.991416+00:00",
+ "last_reported": "2024-12-02T23:08:59.991416+00:00",
+ "last_updated": "2024-12-02T23:08:59.991416+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "azimuth": 270.15,
+ "elevation": -48.37,
+ "friendly_name": "Sun",
+ "next_dawn": "2024-12-03T12:43:12.069747+00:00",
+ "next_dusk": "2024-12-03T23:59:17.247866+00:00",
+ "next_midnight": "2024-12-03T06:21:19+00:00",
+ "next_noon": "2024-12-03T18:21:01+00:00",
+ "next_rising": "2024-12-03T13:10:27.114722+00:00",
+ "next_setting": "2024-12-03T23:32:02.229044+00:00",
+ "rising": false
+ },
+ "context": {
+ "id": "01JE58CABAB2S5HN3XPT4R76ZZ",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sun.sun",
+ "last_changed": "2024-12-02T23:32:00.699271+00:00",
+ "last_reported": "2024-12-03T03:17:48.522474+00:00",
+ "last_updated": "2024-12-03T03:17:48.522474+00:00",
+ "state": "below_horizon"
+ },
+ {
+ "attributes": {
+ "device_class": "timestamp",
+ "friendly_name": "Sun Next dawn"
+ },
+ "context": {
+ "id": "01JE3P9FZTAQEHPZ63GZ6SWKKD",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.sun_next_dawn",
+ "last_changed": "2024-12-02T12:42:27.194381+00:00",
+ "last_reported": "2024-12-02T12:42:27.194381+00:00",
+ "last_updated": "2024-12-02T12:42:27.194381+00:00",
+ "state": "2024-12-03T12:43:12+00:00"
+ },
+ {
+ "attributes": {
+ "device_class": "timestamp",
+ "friendly_name": "Sun Next dusk"
+ },
+ "context": {
+ "id": "01JE4X0PRZX15QTQ1KEXZ0CGNY",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.sun_next_dusk",
+ "last_changed": "2024-12-02T23:59:13.695151+00:00",
+ "last_reported": "2024-12-02T23:59:13.695151+00:00",
+ "last_updated": "2024-12-02T23:59:13.695151+00:00",
+ "state": "2024-12-03T23:59:17+00:00"
+ },
+ {
+ "attributes": {
+ "device_class": "timestamp",
+ "friendly_name": "Sun Next midnight"
+ },
+ "context": {
+ "id": "01JE30EWAVW6FCKVTCV15B15P3",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.sun_next_midnight",
+ "last_changed": "2024-12-02T06:20:55.003357+00:00",
+ "last_reported": "2024-12-02T06:20:55.003357+00:00",
+ "last_updated": "2024-12-02T06:20:55.003357+00:00",
+ "state": "2024-12-03T06:21:19+00:00"
+ },
+ {
+ "attributes": {
+ "device_class": "timestamp",
+ "friendly_name": "Sun Next noon"
+ },
+ "context": {
+ "id": "01JE49MP8CHPMR4TDWKPZEFEEJ",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.sun_next_noon",
+ "last_changed": "2024-12-02T18:20:37.004049+00:00",
+ "last_reported": "2024-12-02T18:20:37.004049+00:00",
+ "last_updated": "2024-12-02T18:20:37.004049+00:00",
+ "state": "2024-12-03T18:21:01+00:00"
+ },
+ {
+ "attributes": {
+ "device_class": "timestamp",
+ "friendly_name": "Sun Next rising"
+ },
+ "context": {
+ "id": "01JE3QVAR1HRD4W5SMTFQG2HAP",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.sun_next_rising",
+ "last_changed": "2024-12-02T13:09:40.225325+00:00",
+ "last_reported": "2024-12-02T13:09:40.225325+00:00",
+ "last_updated": "2024-12-02T13:09:40.225325+00:00",
+ "state": "2024-12-03T13:10:27+00:00"
+ },
+ {
+ "attributes": {
+ "device_class": "timestamp",
+ "friendly_name": "Sun Next setting"
+ },
+ "context": {
+ "id": "01JE4VEW1WFYXVSFAGJ1F9V25N",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.sun_next_setting",
+ "last_changed": "2024-12-02T23:32:00.700201+00:00",
+ "last_reported": "2024-12-02T23:32:00.700201+00:00",
+ "last_updated": "2024-12-02T23:32:00.700201+00:00",
+ "state": "2024-12-03T23:32:02+00:00"
+ },
+ {
+ "attributes": {
+ "device_class": "connectivity",
+ "friendly_name": "ZoneMinder Health",
+ "icon": "mdi:heart-pulse"
+ },
+ "context": {
+ "id": "01JDJQV4P1EZSSC6QNPCSPERKA",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.192_168_100_2_8443",
+ "last_changed": "2024-11-25T22:42:28.673517+00:00",
+ "last_reported": "2024-11-25T22:42:28.673517+00:00",
+ "last_updated": "2024-11-25T22:42:28.673517+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "friendly_name": "Severe Weather Alerts",
+ "icon": "mdi:weather-lightning"
+ },
+ "context": {
+ "id": "01JDQM291EP7Q5YGKCHGX3H25H",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.severe_weather_alerts",
+ "last_changed": "2024-11-27T20:12:40.366505+00:00",
+ "last_reported": "2024-11-27T20:12:40.366505+00:00",
+ "last_updated": "2024-11-27T20:12:40.366505+00:00",
+ "state": "0"
+ },
+ {
+ "attributes": {
+ "friendly_name": "Google en com"
+ },
+ "context": {
+ "id": "01JDJQT7AYFCPW565HE493E4E3",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "tts.google_en_com",
+ "last_changed": "2024-11-25T22:41:58.622077+00:00",
+ "last_reported": "2024-11-25T22:41:58.622077+00:00",
+ "last_updated": "2024-11-25T22:41:58.622077+00:00",
+ "state": "unknown"
+ },
+ {
+ "attributes": {
+ "friendly_name": "Shopping List",
+ "supported_features": 15
+ },
+ "context": {
+ "id": "01JDJQTB70WA4JC7J820V2FN4G",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "todo.shopping_list",
+ "last_changed": "2024-11-25T22:42:02.592056+00:00",
+ "last_reported": "2024-11-25T22:42:02.592056+00:00",
+ "last_updated": "2024-11-25T22:42:02.592056+00:00",
+ "state": "0"
+ },
+ {
+ "attributes": {
+ "friendly_name": "HP LaserJet Pro M404-M405 black cartridge",
+ "marker_high_level": 100,
+ "marker_low_level": 2,
+ "marker_type": "toner-cartridge",
+ "state_class": "measurement",
+ "unit_of_measurement": "%"
+ },
+ "context": {
+ "id": "01JDJQTCJB84QH2ND9GQZD1GKX",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.hp_laserjet_pro_m404_m405_black_cartridge",
+ "last_changed": "2024-11-25T22:42:03.979831+00:00",
+ "last_reported": "2024-11-25T22:42:04.149393+00:00",
+ "last_updated": "2024-11-25T22:42:03.979831+00:00",
+ "state": "90"
+ },
+ {
+ "attributes": {
+ "attribution": "Weather forecast from met.no, delivered by the Norwegian Meteorological Institute.",
+ "cloud_coverage": 19.5,
+ "dew_point": 39,
+ "friendly_name": "Austin Weather",
+ "humidity": 57,
+ "precipitation_unit": "in",
+ "pressure": 1029.6,
+ "pressure_unit": "mbar",
+ "supported_features": 3,
+ "temperature": 54,
+ "temperature_unit": "\u00b0F",
+ "visibility_unit": "mi",
+ "wind_bearing": 42.4,
+ "wind_speed": 6.28,
+ "wind_speed_unit": "mph"
+ },
+ "context": {
+ "id": "01JE599ME32V4PG4RQ0C44Q0F0",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "weather.forecast_home_2",
+ "last_changed": "2024-12-02T07:13:37.274242+00:00",
+ "last_reported": "2024-12-03T03:33:49.123833+00:00",
+ "last_updated": "2024-12-03T03:33:49.123833+00:00",
+ "state": "partlycloudy"
+ },
+ {
+ "attributes": {
+ "attribution": "Weather forecast from met.no, delivered by the Norwegian Meteorological Institute.",
+ "cloud_coverage": 69.5,
+ "dew_point": 47,
+ "friendly_name": "Forecast Antibes",
+ "humidity": 77,
+ "precipitation_unit": "in",
+ "pressure": 29.98,
+ "pressure_unit": "inHg",
+ "supported_features": 3,
+ "temperature": 53,
+ "temperature_unit": "\u00b0F",
+ "visibility_unit": "mi",
+ "wind_bearing": 21.8,
+ "wind_speed": 12.99,
+ "wind_speed_unit": "mph"
+ },
+ "context": {
+ "id": "01JE565F0PDE0A6CK8M2XNKHEA",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "weather.forecast_antibes",
+ "last_changed": "2024-12-02T18:06:06.895107+00:00",
+ "last_reported": "2024-12-03T02:39:06.774917+00:00",
+ "last_updated": "2024-12-03T02:39:06.774917+00:00",
+ "state": "partlycloudy"
+ },
+ {
+ "attributes": {
+ "attribution": "Weather forecast from met.no, delivered by the Norwegian Meteorological Institute.",
+ "cloud_coverage": 1.6,
+ "dew_point": 25,
+ "friendly_name": "Forecast Commack",
+ "humidity": 72,
+ "precipitation_unit": "in",
+ "pressure": 30.16,
+ "pressure_unit": "inHg",
+ "supported_features": 3,
+ "temperature": 33,
+ "temperature_unit": "\u00b0F",
+ "visibility_unit": "mi",
+ "wind_bearing": 310.8,
+ "wind_speed": 12.99,
+ "wind_speed_unit": "mph"
+ },
+ "context": {
+ "id": "01JE589612HE7NAHZ7XJWHX11A",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "weather.forecast_commack",
+ "last_changed": "2024-12-02T22:06:05.781601+00:00",
+ "last_reported": "2024-12-03T03:16:05.794451+00:00",
+ "last_updated": "2024-12-03T03:16:05.794451+00:00",
+ "state": "clear-night"
+ },
+ {
+ "attributes": {
+ "attribution": "Weather forecast from met.no, delivered by the Norwegian Meteorological Institute.",
+ "cloud_coverage": 6.2,
+ "dew_point": 50,
+ "friendly_name": "Forecast Delray Beach",
+ "humidity": 63,
+ "precipitation_unit": "in",
+ "pressure": 30.25,
+ "pressure_unit": "inHg",
+ "supported_features": 3,
+ "temperature": 62,
+ "temperature_unit": "\u00b0F",
+ "visibility_unit": "mi",
+ "wind_bearing": 337.7,
+ "wind_speed": 17.21,
+ "wind_speed_unit": "mph"
+ },
+ "context": {
+ "id": "01JE56J85BGN6QE6NPDEMQ1A6M",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "weather.forecast_delray_beach",
+ "last_changed": "2024-12-02T22:54:05.754131+00:00",
+ "last_reported": "2024-12-03T02:46:05.739769+00:00",
+ "last_updated": "2024-12-03T02:46:05.739769+00:00",
+ "state": "clear-night"
+ },
+ {
+ "attributes": {
+ "friendly_name": "HighCamera State",
+ "icon": "mdi:record-rec"
+ },
+ "context": {
+ "id": "01JDJQVA15DWAZEPA2AF4PC64G",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "switch.highcamera_state",
+ "last_changed": "2024-11-25T22:42:34.149924+00:00",
+ "last_reported": "2024-11-25T22:42:34.149924+00:00",
+ "last_updated": "2024-11-25T22:42:34.149924+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "friendly_name": "BackCamera State",
+ "icon": "mdi:record-rec"
+ },
+ "context": {
+ "id": "01JE56QPD78R64C61S52210M3X",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "switch.backcamera_state",
+ "last_changed": "2024-12-03T02:49:04.167562+00:00",
+ "last_reported": "2024-12-03T02:49:04.167562+00:00",
+ "last_updated": "2024-12-03T02:49:04.167562+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "friendly_name": "FrontCamera State",
+ "icon": "mdi:record-rec"
+ },
+ "context": {
+ "id": "01JDJQVA725BG2CM1YDZ6DJN59",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "switch.frontcamera_state",
+ "last_changed": "2024-11-25T22:42:34.338995+00:00",
+ "last_reported": "2024-11-25T22:42:34.338995+00:00",
+ "last_updated": "2024-11-25T22:42:34.338995+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "friendly_name": "PatioCamera State",
+ "icon": "mdi:record-rec"
+ },
+ "context": {
+ "id": "01JE56QPJS7ZJNHZ3YX3PW5N6R",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "switch.patiocamera_state",
+ "last_changed": "2024-12-03T02:49:04.345207+00:00",
+ "last_reported": "2024-12-03T02:49:04.345207+00:00",
+ "last_updated": "2024-12-03T02:49:04.345207+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "friendly_name": "SideCamera State",
+ "icon": "mdi:record-rec"
+ },
+ "context": {
+ "id": "01JE56QPNGQBWMGX1QWY9PGWPY",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "switch.sidecamera_state",
+ "last_changed": "2024-12-03T02:49:04.432763+00:00",
+ "last_reported": "2024-12-03T02:49:04.432763+00:00",
+ "last_updated": "2024-12-03T02:49:04.432763+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "friendly_name": "DriveCamera State",
+ "icon": "mdi:record-rec"
+ },
+ "context": {
+ "id": "01JDJQVAF8YNVZG7VR0MXPN2JH",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "switch.drivecamera_state",
+ "last_changed": "2024-11-25T22:42:34.600178+00:00",
+ "last_reported": "2024-11-25T22:42:34.600178+00:00",
+ "last_updated": "2024-11-25T22:42:34.600178+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "friendly_name": "PoolCamera State",
+ "icon": "mdi:record-rec"
+ },
+ "context": {
+ "id": "01JE56QPV10YMG2JVYJWV9YGZ0",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "switch.poolcamera_state",
+ "last_changed": "2024-12-03T02:49:04.609188+00:00",
+ "last_reported": "2024-12-03T02:49:04.609188+00:00",
+ "last_updated": "2024-12-03T02:49:04.609188+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "friendly_name": "CarCamera State",
+ "icon": "mdi:record-rec"
+ },
+ "context": {
+ "id": "01JE56SHGTS82ZJRB28N9K61AW",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "switch.carcamera_state",
+ "last_changed": "2024-12-03T02:50:04.698981+00:00",
+ "last_reported": "2024-12-03T02:50:04.698981+00:00",
+ "last_updated": "2024-12-03T02:50:04.698981+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "friendly_name": "GarageCamera State",
+ "icon": "mdi:record-rec"
+ },
+ "context": {
+ "id": "01JE56TEWV5QCP0SYD9J528F9B",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "switch.garagecamera_state",
+ "last_changed": "2024-12-03T02:50:34.779475+00:00",
+ "last_reported": "2024-12-03T02:50:34.779475+00:00",
+ "last_updated": "2024-12-03T02:50:34.779475+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "command_set": "PCL5c,PCLXL,POSTSCRIPT,PDF,PJL,Automatic,JPEG,AppleRaster,PWGRaster,PCLM,802.3,DESKJET,DYN",
+ "device_class": "enum",
+ "friendly_name": "HP LaserJet Pro M404-M405",
+ "info": "HP LaserJet Pro M404-M405 [C1C4EA]",
+ "location": "",
+ "options": [
+ "idle",
+ "printing",
+ "stopped"
+ ],
+ "serial": "VND3F07336",
+ "state_message": "",
+ "state_reason": null,
+ "uri_supported": "ipp://192.168.100.250/ipp/print,ipps://192.168.100.250:631/ipp/print"
+ },
+ "context": {
+ "id": "01JDJQTCQNNFG8KQD03ZYWBJBH",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.hp_laserjet_pro_m404_m405",
+ "last_changed": "2024-11-25T22:42:04.149906+00:00",
+ "last_reported": "2024-11-25T22:42:04.149906+00:00",
+ "last_updated": "2024-11-25T22:42:04.149906+00:00",
+ "state": "idle"
+ },
+ {
+ "attributes": {
+ "device_class": "door",
+ "friendly_name": "Front Door",
+ "icon": "mdi:door",
+ "insteon_address": "2D.4A.03",
+ "insteon_group": 1
+ },
+ "context": {
+ "id": "01JE4KRY5J7GHSH1V1KM6D4622",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.open_close_sensor_2d_4a_03",
+ "last_changed": "2024-12-02T21:17:41.938411+00:00",
+ "last_reported": "2024-12-02T21:17:41.938411+00:00",
+ "last_updated": "2024-12-02T21:17:41.938411+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "device_class": "door",
+ "friendly_name": "Master Bath Door",
+ "icon": "mdi:door-sliding",
+ "insteon_address": "32.50.1C",
+ "insteon_group": 1
+ },
+ "context": {
+ "id": "01JDJQTFY4XB6G9DZR4PCG6SYN",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.open_close_sensor_32_50_1c",
+ "last_changed": "2024-11-25T22:42:07.428855+00:00",
+ "last_reported": "2024-11-25T22:42:07.428855+00:00",
+ "last_updated": "2024-11-25T22:42:07.428855+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "device_class": "door",
+ "friendly_name": "Back Patio Door",
+ "icon": "mdi:door-sliding",
+ "insteon_address": "2D.6F.D5",
+ "insteon_group": 1
+ },
+ "context": {
+ "id": "01JE4C17W48E53SS3H701HKHHZ",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.open_close_sensor_2d_6f_d5",
+ "last_changed": "2024-12-02T19:02:25.412638+00:00",
+ "last_reported": "2024-12-02T19:02:25.412638+00:00",
+ "last_updated": "2024-12-02T19:02:25.412638+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "device_class": "door",
+ "friendly_name": "Garage Outer Door",
+ "icon": "mdi:door",
+ "insteon_address": "2D.79.55",
+ "insteon_group": 1
+ },
+ "context": {
+ "id": "01JDJR4QW40J5N90NHR89MRS22",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.open_close_sensor_2d_79_55",
+ "last_changed": "2024-11-25T22:47:43.236919+00:00",
+ "last_reported": "2024-11-25T22:47:43.236919+00:00",
+ "last_updated": "2024-11-25T22:47:43.236919+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "device_class": "door",
+ "friendly_name": "Side Deck Door",
+ "icon": "mdi:door",
+ "insteon_address": "2D.71.73",
+ "insteon_group": 1
+ },
+ "context": {
+ "id": "01JE4XBGCB1VEV9VZS0KXQTAYK",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.open_close_sensor_2d_71_73",
+ "last_changed": "2024-12-03T00:05:07.595648+00:00",
+ "last_reported": "2024-12-03T00:05:07.595648+00:00",
+ "last_updated": "2024-12-03T00:05:07.595648+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "device_class": "garage_door",
+ "friendly_name": "Garage Overhead Door",
+ "icon": "mdi:garage",
+ "insteon_address": "2D.23.5C",
+ "insteon_group": 1
+ },
+ "context": {
+ "id": "01JE55K4N1GGE5118G4VSB85A1",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.open_close_sensor_2d_23_5c",
+ "last_changed": "2024-12-03T02:29:06.337173+00:00",
+ "last_reported": "2024-12-03T02:29:06.337173+00:00",
+ "last_updated": "2024-12-03T02:29:06.337173+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "device_class": "motion",
+ "friendly_name": "Side Deck Motion",
+ "insteon_address": "28.5B.C1",
+ "insteon_group": 1
+ },
+ "context": {
+ "id": "01JE4XD4B0RJHCS9NJFPABNVA1",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.motion_sensor_28_5b_c1_motion",
+ "last_changed": "2024-12-03T00:06:00.800925+00:00",
+ "last_reported": "2024-12-03T00:06:00.800925+00:00",
+ "last_updated": "2024-12-03T00:06:00.800925+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "device_class": "light",
+ "friendly_name": "Side Deck Motion Light",
+ "insteon_address": "28.5B.C1",
+ "insteon_group": 2
+ },
+ "context": {
+ "id": "01JDJQTFYKVK2ZGTMRK04TBDAA",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.motion_sensor_28_5b_c1_light",
+ "last_changed": "2024-11-25T22:42:07.443544+00:00",
+ "last_reported": "2024-11-25T22:42:07.443544+00:00",
+ "last_updated": "2024-11-25T22:42:07.443544+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "device_class": "battery",
+ "friendly_name": "Side Deck Motion Battery",
+ "insteon_address": "28.5B.C1",
+ "insteon_group": 3
+ },
+ "context": {
+ "id": "01JDJQTFYMEM232A0F9NBZ2NAR",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.motion_sensor_28_5b_c1_battery",
+ "last_changed": "2024-11-25T22:42:07.444282+00:00",
+ "last_reported": "2024-11-25T22:42:07.444282+00:00",
+ "last_updated": "2024-11-25T22:42:07.444282+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "device_class": "motion",
+ "friendly_name": "Back Patio Motion",
+ "insteon_address": "2D.69.4B",
+ "insteon_group": 1
+ },
+ "context": {
+ "id": "01JE4XCGGNNVWSRHN7VZFDNANJ",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.motion_sensor_2d_69_4b_motion",
+ "last_changed": "2024-12-03T00:05:40.501330+00:00",
+ "last_reported": "2024-12-03T00:05:40.501330+00:00",
+ "last_updated": "2024-12-03T00:05:40.501330+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "device_class": "light",
+ "friendly_name": "Back Patio Motion Light",
+ "insteon_address": "2D.69.4B",
+ "insteon_group": 2
+ },
+ "context": {
+ "id": "01JDJQTFYSMFYW6CE26HY2HGN8",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.motion_sensor_2d_69_4b_light",
+ "last_changed": "2024-11-25T22:42:07.449396+00:00",
+ "last_reported": "2024-11-25T22:42:07.449396+00:00",
+ "last_updated": "2024-11-25T22:42:07.449396+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "device_class": "battery",
+ "friendly_name": "Back Patio Motion Battery",
+ "insteon_address": "2D.69.4B",
+ "insteon_group": 3
+ },
+ "context": {
+ "id": "01JDJQTFYT2HZMZG025CV00CES",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.motion_sensor_2d_69_4b_battery",
+ "last_changed": "2024-11-25T22:42:07.450088+00:00",
+ "last_reported": "2024-11-25T22:42:07.450088+00:00",
+ "last_updated": "2024-11-25T22:42:07.450088+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "device_class": "motion",
+ "friendly_name": "Driveway Motion",
+ "insteon_address": "31.DD.A6",
+ "insteon_group": 1
+ },
+ "context": {
+ "id": "01JE55MJFQEBVM96H56QGS64YX",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.motion_sensor_31_dd_a6_motion",
+ "last_changed": "2024-12-03T02:29:53.271766+00:00",
+ "last_reported": "2024-12-03T02:29:53.271766+00:00",
+ "last_updated": "2024-12-03T02:29:53.271766+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "device_class": "light",
+ "friendly_name": "Driveway Motion Light",
+ "insteon_address": "31.DD.A6",
+ "insteon_group": 2
+ },
+ "context": {
+ "id": "01JDJQTFYY2SEPCDPYKZM5DQWX",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.motion_sensor_31_dd_a6_light",
+ "last_changed": "2024-11-25T22:42:07.454681+00:00",
+ "last_reported": "2024-11-25T22:42:07.454681+00:00",
+ "last_updated": "2024-11-25T22:42:07.454681+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "device_class": "battery",
+ "friendly_name": "Driveway Motion Battery",
+ "insteon_address": "31.DD.A6",
+ "insteon_group": 3
+ },
+ "context": {
+ "id": "01JDJQTFYZBSENGPJX5GXR9HR6",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.motion_sensor_31_dd_a6_battery",
+ "last_changed": "2024-11-25T22:42:07.455372+00:00",
+ "last_reported": "2024-11-25T22:42:07.455372+00:00",
+ "last_updated": "2024-11-25T22:42:07.455372+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "device_class": "motion",
+ "friendly_name": "Master Entry Motion",
+ "insteon_address": "2D.6A.C9",
+ "insteon_group": 1
+ },
+ "context": {
+ "id": "01JDJQTFZ0GQ7NPPENZZQF392J",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.motion_sensor_2d_6a_c9_motion",
+ "last_changed": "2024-11-25T22:42:07.456266+00:00",
+ "last_reported": "2024-11-25T22:42:07.456266+00:00",
+ "last_updated": "2024-11-25T22:42:07.456266+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "device_class": "light",
+ "friendly_name": "Master Entry Motion Light",
+ "insteon_address": "2D.6A.C9",
+ "insteon_group": 2
+ },
+ "context": {
+ "id": "01JDJQTFZ35KH86Z5Z3BJQ3PHM",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.motion_sensor_2d_6a_c9_light",
+ "last_changed": "2024-11-25T22:42:07.459986+00:00",
+ "last_reported": "2024-11-25T22:42:07.459986+00:00",
+ "last_updated": "2024-11-25T22:42:07.459986+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "device_class": "battery",
+ "friendly_name": "Master Entry Motion Battery",
+ "insteon_address": "2D.6A.C9",
+ "insteon_group": 3
+ },
+ "context": {
+ "id": "01JDJQTFZ48CCQ7HVWMPQCBJDT",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.motion_sensor_2d_6a_c9_battery",
+ "last_changed": "2024-11-25T22:42:07.460712+00:00",
+ "last_reported": "2024-11-25T22:42:07.460712+00:00",
+ "last_updated": "2024-11-25T22:42:07.460712+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "device_class": "motion",
+ "friendly_name": "Front Porch Motion",
+ "insteon_address": "2D.68.BE",
+ "insteon_group": 1
+ },
+ "context": {
+ "id": "01JE4PZR27WM75YKD3NMXQJDPF",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.motion_sensor_2d_68_be_motion",
+ "last_changed": "2024-12-02T22:13:50.791592+00:00",
+ "last_reported": "2024-12-02T22:13:50.791592+00:00",
+ "last_updated": "2024-12-02T22:13:50.791592+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "device_class": "light",
+ "friendly_name": "Front Porch Motion Light",
+ "insteon_address": "2D.68.BE",
+ "insteon_group": 2
+ },
+ "context": {
+ "id": "01JDJQTFZ6ZWQY8TETPHX24N60",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.motion_sensor_2d_68_be_light",
+ "last_changed": "2024-11-25T22:42:07.462445+00:00",
+ "last_reported": "2024-11-25T22:42:07.462445+00:00",
+ "last_updated": "2024-11-25T22:42:07.462445+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "device_class": "battery",
+ "friendly_name": "Front Porch Motion Battery",
+ "insteon_address": "2D.68.BE",
+ "insteon_group": 3
+ },
+ "context": {
+ "id": "01JDJQTFZ8V4TVKR4M5QBX4SSQ",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.motion_sensor_2d_68_be_battery",
+ "last_changed": "2024-11-25T22:42:07.464615+00:00",
+ "last_reported": "2024-11-25T22:42:07.464615+00:00",
+ "last_updated": "2024-11-25T22:42:07.464615+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "brightness": 255,
+ "color_mode": "brightness",
+ "friendly_name": "Dining Room Light",
+ "insteon_address": "17.2E.C3",
+ "insteon_group": 1,
+ "supported_color_modes": [
+ "brightness"
+ ],
+ "supported_features": 0
+ },
+ "context": {
+ "id": "01JE4SQY7SGDKP51GHZWTY7ZJ7",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "light.switchlinc_dimmer_17_2e_c3",
+ "last_changed": "2024-12-02T23:02:01.119014+00:00",
+ "last_reported": "2024-12-02T23:02:01.119014+00:00",
+ "last_updated": "2024-12-02T23:02:01.119014+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "brightness": null,
+ "color_mode": null,
+ "friendly_name": "Office Light & Keypad Main",
+ "insteon_address": "23.D0.86",
+ "insteon_group": 1,
+ "supported_color_modes": [
+ "brightness"
+ ],
+ "supported_features": 0
+ },
+ "context": {
+ "id": "01JDWCRNJZNF11FVJP68E97ZCR",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "light.keypadlinc_dimmer_23_d0_86_main",
+ "last_changed": "2024-11-29T16:41:17.663616+00:00",
+ "last_reported": "2024-11-29T16:41:17.663616+00:00",
+ "last_updated": "2024-11-29T16:41:17.663616+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "friendly_name": "Fireplace Light",
+ "icon": "mdi:lightbulb",
+ "insteon_address": "18.36.CB",
+ "insteon_group": 1
+ },
+ "context": {
+ "id": "01JE4T4QPQJA0DDH757DCC6K7M",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "switch.switchlinc_relay_18_36_cb",
+ "last_changed": "2024-12-02T23:08:59.991237+00:00",
+ "last_reported": "2024-12-02T23:08:59.991237+00:00",
+ "last_updated": "2024-12-02T23:08:59.991237+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "friendly_name": "Living Room Light",
+ "icon": "mdi:lightbulb",
+ "insteon_address": "43.54.48",
+ "insteon_group": 1
+ },
+ "context": {
+ "id": "01JE2XVWMWZJVTFA1JSBC76TDA",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "switch.switchlinc_relay_dual_band_43_54_48",
+ "last_changed": "2024-12-02T05:35:35.580881+00:00",
+ "last_reported": "2024-12-02T05:35:35.580881+00:00",
+ "last_updated": "2024-12-02T05:35:35.580881+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "friendly_name": "Kitchen Cooktop Light",
+ "icon": "mdi:lightbulb",
+ "insteon_address": "18.36.41",
+ "insteon_group": 1
+ },
+ "context": {
+ "id": "01JE4X5SVR69D47WR7VMKKJRG6",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "switch.switchlinc_relay_18_36_41",
+ "last_changed": "2024-12-03T00:02:01.877257+00:00",
+ "last_reported": "2024-12-03T00:02:01.877257+00:00",
+ "last_updated": "2024-12-03T00:02:01.877257+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "friendly_name": "Deck Lights",
+ "icon": "mdi:lightbulb",
+ "insteon_address": "23.FA.31",
+ "insteon_group": 1
+ },
+ "context": {
+ "id": "01JE4X5SVR69D47WR7VMKKJRG6",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "switch.switchlinc_relay_dual_band_23_fa_31",
+ "last_changed": "2024-12-03T00:02:01.075667+00:00",
+ "last_reported": "2024-12-03T00:02:01.075667+00:00",
+ "last_updated": "2024-12-03T00:02:01.075667+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "friendly_name": "Side Door Light",
+ "icon": "mdi:lightbulb",
+ "insteon_address": "23.EE.08",
+ "insteon_group": 1
+ },
+ "context": {
+ "id": "01JDJQTG11CDPAF1N1404VPSP8",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "switch.switchlinc_relay_dual_band_23_ee_08",
+ "last_changed": "2024-11-25T22:42:07.521625+00:00",
+ "last_reported": "2024-11-25T22:42:12.515707+00:00",
+ "last_updated": "2024-11-25T22:42:07.521625+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "friendly_name": "Main Kitchen Light",
+ "icon": "mdi:lightbulb",
+ "insteon_address": "70.63.E1",
+ "insteon_group": 1
+ },
+ "context": {
+ "id": "01JE4T803HR9QFJRM4DM1TG6K0",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "switch.switchlinc_relay_dual_band_70_63_e1",
+ "last_changed": "2024-12-02T23:10:46.897596+00:00",
+ "last_reported": "2024-12-02T23:10:46.897596+00:00",
+ "last_updated": "2024-12-02T23:10:46.897596+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "device_class": "outlet",
+ "friendly_name": "Living Room Outlet",
+ "insteon_address": "19.9E.0D",
+ "insteon_group": 1
+ },
+ "context": {
+ "id": "01JDN8FDY67CYC8GPAF5QJWGR2",
+ "parent_id": null,
+ "user_id": "f6707281e954491cbccb97307afa2c0e"
+ },
+ "entity_id": "switch.outletlinc_relay_19_9e_0d",
+ "last_changed": "2024-11-26T22:11:41.537737+00:00",
+ "last_reported": "2024-11-26T22:11:41.537737+00:00",
+ "last_updated": "2024-11-26T22:11:41.537737+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "friendly_name": "Office Outlet (east)",
+ "icon": "mdi:power-plug",
+ "insteon_address": "22.CE.EB",
+ "insteon_group": 1
+ },
+ "context": {
+ "id": "01JDWMG4VZ8BYYQ7R8NK1J4SP7",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "switch.outletlinc_relay_22_ce_eb",
+ "last_changed": "2024-11-25T22:42:07.531151+00:00",
+ "last_reported": "2024-11-29T18:56:27.007149+00:00",
+ "last_updated": "2024-11-29T18:56:27.007149+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "friendly_name": "Office Light & Keypad Button A",
+ "insteon_address": "23.D0.86",
+ "insteon_group": 3
+ },
+ "context": {
+ "id": "01JDJQTG1C8JC43M304ZZ78QPM",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "switch.keypadlinc_dimmer_23_d0_86_button_a",
+ "last_changed": "2024-11-25T22:42:07.532022+00:00",
+ "last_reported": "2024-11-25T22:42:07.532022+00:00",
+ "last_updated": "2024-11-25T22:42:07.532022+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "friendly_name": "Office Light & Keypad Button B",
+ "insteon_address": "23.D0.86",
+ "insteon_group": 4
+ },
+ "context": {
+ "id": "01JDJQTG1CGAJ4XWBJ1YPFTK3A",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "switch.keypadlinc_dimmer_23_d0_86_button_b",
+ "last_changed": "2024-11-25T22:42:07.532762+00:00",
+ "last_reported": "2024-11-25T22:42:07.532762+00:00",
+ "last_updated": "2024-11-25T22:42:07.532762+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "friendly_name": "Office Light & Keypad Button C",
+ "insteon_address": "23.D0.86",
+ "insteon_group": 5
+ },
+ "context": {
+ "id": "01JDJQTG1D7DDQMWGEJMQQCJDH",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "switch.keypadlinc_dimmer_23_d0_86_button_c",
+ "last_changed": "2024-11-25T22:42:07.533437+00:00",
+ "last_reported": "2024-11-25T22:42:07.533437+00:00",
+ "last_updated": "2024-11-25T22:42:07.533437+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "friendly_name": "Office Light & Keypad Button D",
+ "insteon_address": "23.D0.86",
+ "insteon_group": 6
+ },
+ "context": {
+ "id": "01JDJQTG1E5HXGRS51YYW91E55",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "switch.keypadlinc_dimmer_23_d0_86_button_d",
+ "last_changed": "2024-11-25T22:42:07.534145+00:00",
+ "last_reported": "2024-11-25T22:42:07.534145+00:00",
+ "last_updated": "2024-11-25T22:42:07.534145+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "device_class": "connectivity",
+ "friendly_name": "Internet Access",
+ "round_trip_time_avg": "6.539",
+ "round_trip_time_max": "6.623",
+ "round_trip_time_mdev": "0.067",
+ "round_trip_time_min": "6.466"
+ },
+ "context": {
+ "id": "01JE59BR2CG0A4AMN437MMW9N6",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.8_8_8_8",
+ "last_changed": "2024-11-25T22:42:07.570329+00:00",
+ "last_reported": "2024-12-03T03:34:58.380015+00:00",
+ "last_updated": "2024-12-03T03:34:58.380015+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "device_class": "connectivity",
+ "friendly_name": "Bordeaux Server",
+ "round_trip_time_avg": "0.035",
+ "round_trip_time_max": "0.043",
+ "round_trip_time_mdev": "0.005",
+ "round_trip_time_min": "0.028"
+ },
+ "context": {
+ "id": "01JE59BQ7GHZSWMPR8HP1MPRQH",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.192_168_100_2",
+ "last_changed": "2024-11-25T22:42:07.579659+00:00",
+ "last_reported": "2024-12-03T03:34:57.520288+00:00",
+ "last_updated": "2024-12-03T03:34:57.520288+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "device_class": "connectivity",
+ "friendly_name": "Internal Network",
+ "round_trip_time_avg": "0.191",
+ "round_trip_time_max": "0.204",
+ "round_trip_time_mdev": "0.008",
+ "round_trip_time_min": "0.178"
+ },
+ "context": {
+ "id": "01JE59BQ7N1RW8CWEN5Q4PFGGV",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.192_168_100_1",
+ "last_changed": "2024-11-25T22:42:07.585445+00:00",
+ "last_reported": "2024-12-03T03:34:57.525560+00:00",
+ "last_updated": "2024-12-03T03:34:57.525560+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "device_class": "connectivity",
+ "friendly_name": "Cassandra Server",
+ "round_trip_time_avg": "0.226",
+ "round_trip_time_max": "0.245",
+ "round_trip_time_mdev": "0.014",
+ "round_trip_time_min": "0.200"
+ },
+ "context": {
+ "id": "01JE59C25GXM93RGHB6RVCJCN7",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.192_168_100_4",
+ "last_changed": "2024-11-25T22:42:07.587454+00:00",
+ "last_reported": "2024-12-03T03:35:08.720364+00:00",
+ "last_updated": "2024-12-03T03:35:08.720364+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "device_class": "connectivity",
+ "friendly_name": "Groovy Desktop",
+ "round_trip_time_avg": "0.285",
+ "round_trip_time_max": "0.337",
+ "round_trip_time_mdev": "0.027",
+ "round_trip_time_min": "0.263"
+ },
+ "context": {
+ "id": "01JE59BQ7GMDQJ96T9PQSD3G9M",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "binary_sensor.192_168_100_6",
+ "last_changed": "2024-11-25T22:42:07.593820+00:00",
+ "last_reported": "2024-12-03T03:34:57.520625+00:00",
+ "last_updated": "2024-12-03T03:34:57.520625+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "friendly_name": "WAN Address",
+ "icon": "mdi:ip"
+ },
+ "context": {
+ "id": "01JDJQTG72X7C51KZFATSYZ3AA",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.wan_address",
+ "last_changed": "2024-11-25T22:42:07.714967+00:00",
+ "last_reported": "2024-11-25T22:42:07.714967+00:00",
+ "last_updated": "2024-11-25T22:42:07.714967+00:00",
+ "state": "136.62.87.253"
+ },
+ {
+ "attributes": {
+ "friendly_name": "House maintenance",
+ "icon": "mdi:shovel",
+ "supported_features": 127
+ },
+ "context": {
+ "id": "01JDJQTGC6WYTEXD2G8E38MRVQ",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "todo.house_maintenance",
+ "last_changed": "2024-11-25T22:42:07.878619+00:00",
+ "last_reported": "2024-11-25T22:42:07.878619+00:00",
+ "last_updated": "2024-11-25T22:42:07.878619+00:00",
+ "state": "0"
+ },
+ {
+ "attributes": {
+ "friendly_name": "Finances",
+ "icon": "mdi:currency-usd",
+ "supported_features": 127
+ },
+ "context": {
+ "id": "01JDJQTGC7AKSFY6AQ573M7BCF",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "todo.finances",
+ "last_changed": "2024-11-25T22:42:07.879127+00:00",
+ "last_reported": "2024-11-25T22:42:07.879127+00:00",
+ "last_updated": "2024-11-25T22:42:07.879127+00:00",
+ "state": "0"
+ },
+ {
+ "attributes": {
+ "current": 0,
+ "friendly_name": "Before Sunset",
+ "id": "1722910476870",
+ "last_triggered": "2024-12-02T23:02:00.697478+00:00",
+ "mode": "single"
+ },
+ "context": {
+ "id": "01JE4SQY7SGDKP51GHZWTY7ZJ7",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "automation.before_sunset",
+ "last_changed": "2024-11-25T22:42:08.094136+00:00",
+ "last_reported": "2024-12-02T23:02:01.873630+00:00",
+ "last_updated": "2024-12-02T23:02:01.873630+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "current": 0,
+ "friendly_name": "After Sunset",
+ "id": "1722910547631",
+ "last_triggered": "2024-12-03T00:02:00.696241+00:00",
+ "mode": "single"
+ },
+ "context": {
+ "id": "01JE4X5SVR69D47WR7VMKKJRG6",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "automation.after_sunset",
+ "last_changed": "2024-11-25T22:42:08.094378+00:00",
+ "last_reported": "2024-12-03T00:02:01.881128+00:00",
+ "last_updated": "2024-12-03T00:02:01.881128+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "current": 0,
+ "friendly_name": "Pre-sleep Time",
+ "id": "1722910637175",
+ "last_triggered": "2024-12-02T04:00:00.302860+00:00",
+ "mode": "single"
+ },
+ "context": {
+ "id": "01JE2RCVSEWM7K75CB8HRDKPFP",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "automation.pre_sleep_time",
+ "last_changed": "2024-11-25T22:42:08.094572+00:00",
+ "last_reported": "2024-12-02T04:00:01.541680+00:00",
+ "last_updated": "2024-12-02T04:00:01.541680+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "current": 0,
+ "friendly_name": "Sleep Time",
+ "id": "1722910694959",
+ "last_triggered": "2024-12-02T05:00:00.204833+00:00",
+ "mode": "single"
+ },
+ "context": {
+ "id": "01JE2VTQACZGAWM0NRNT6SAV9B",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "automation.sleep_time",
+ "last_changed": "2024-11-25T22:42:08.094761+00:00",
+ "last_reported": "2024-12-02T05:00:00.582009+00:00",
+ "last_updated": "2024-12-02T05:00:00.582009+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "current": 0,
+ "friendly_name": "Deck Lights Off",
+ "id": "1722910724832",
+ "last_triggered": "2024-12-02T05:30:00.065994+00:00",
+ "mode": "single"
+ },
+ "context": {
+ "id": "01JE2XHN01GCF5KVKYP0WEMGGG",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "automation.deck_lights_off",
+ "last_changed": "2024-11-25T22:42:08.094940+00:00",
+ "last_reported": "2024-12-02T05:30:00.439823+00:00",
+ "last_updated": "2024-12-02T05:30:00.439823+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "current": 0,
+ "friendly_name": "Switch to HomeDay Camera Mode",
+ "id": "1723244134721",
+ "last_triggered": "2024-12-02T13:09:40.221578+00:00",
+ "mode": "single"
+ },
+ "context": {
+ "id": "01JE3QVAQX5XXVQAM2CZFK44TT",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "automation.switch_to_homeday_camera_mode",
+ "last_changed": "2024-11-25T22:42:08.095127+00:00",
+ "last_reported": "2024-12-02T13:09:40.222427+00:00",
+ "last_updated": "2024-12-02T13:09:40.222427+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "current": 0,
+ "friendly_name": "Set to HomeNight Camera Mode",
+ "id": "1723244218673",
+ "last_triggered": "2024-12-02T05:00:00.271741+00:00",
+ "mode": "single"
+ },
+ "context": {
+ "id": "01JE2VTQCFRSGY501WP220X6GS",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "automation.set_to_homenight_camera_state",
+ "last_changed": "2024-11-25T22:42:08.095468+00:00",
+ "last_reported": "2024-12-02T05:00:00.272477+00:00",
+ "last_updated": "2024-12-02T05:00:00.272477+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "current": 0,
+ "friendly_name": "Front Motion",
+ "id": "1723304564522",
+ "last_triggered": "2024-08-10T17:15:05.832422+00:00",
+ "mode": "single"
+ },
+ "context": {
+ "id": "01JDJQTGJZ5CZBKVB8EJ0MFEJN",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "automation.front_motion",
+ "last_changed": "2024-11-25T22:42:08.095632+00:00",
+ "last_reported": "2024-11-25T22:42:08.095632+00:00",
+ "last_updated": "2024-11-25T22:42:08.095632+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "current": 0,
+ "friendly_name": "Severe Weather Alert",
+ "id": "1723436201934",
+ "last_triggered": "2024-11-17T11:47:05.902399+00:00",
+ "mode": "single"
+ },
+ "context": {
+ "id": "01JDJQTGJZXNENJ2B09VEPJEWS",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "automation.severe_weather_alert",
+ "last_changed": "2024-11-25T22:42:08.095821+00:00",
+ "last_reported": "2024-11-25T22:42:08.095821+00:00",
+ "last_updated": "2024-11-25T22:42:08.095821+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "current": 0,
+ "friendly_name": "Front Camera Recording",
+ "id": "1723490543413",
+ "last_triggered": "2024-11-30T02:13:45.358137+00:00",
+ "mode": "single"
+ },
+ "context": {
+ "id": "01JDXDGW8DX5KKY59P5S91ZSE2",
+ "parent_id": "01JDXDGT9XD74EH88MHYKF88PG",
+ "user_id": null
+ },
+ "entity_id": "automation.front_camera_recording",
+ "last_changed": "2024-11-25T22:42:08.096058+00:00",
+ "last_reported": "2024-11-30T02:13:45.359648+00:00",
+ "last_updated": "2024-11-30T02:13:45.359648+00:00",
+ "state": "on"
+ },
+ {
+ "attributes": {
+ "friendly_name": "Events",
+ "supported_features": 3
+ },
+ "context": {
+ "id": "01JDJQTHGA0RDBQ1CDCDQDEA88",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "calendar.events",
+ "last_changed": "2024-11-25T22:42:09.034123+00:00",
+ "last_reported": "2024-11-25T22:42:09.034123+00:00",
+ "last_updated": "2024-11-25T22:42:09.034123+00:00",
+ "state": "unavailable"
+ },
+ {
+ "attributes": {
+ "all_day": true,
+ "description": "",
+ "end_time": "2024-12-07 00:00:00",
+ "friendly_name": "Maintenance",
+ "location": "Cars",
+ "message": "Change Oil in Cars",
+ "offset_reached": false,
+ "start_time": "2024-12-06 00:00:00",
+ "supported_features": 3
+ },
+ "context": {
+ "id": "01JE2BBMG2MAAKQDX4GF66ZK6F",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "calendar.maintenance",
+ "last_changed": "2024-12-02T00:12:08.578806+00:00",
+ "last_reported": "2024-12-02T00:12:08.578806+00:00",
+ "last_updated": "2024-12-02T00:12:08.578806+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "all_day": true,
+ "description": "Bills go to email, pay manually paid through UFCU Bill Pay (Trust account).",
+ "end_time": "2024-12-11 00:00:00",
+ "friendly_name": "Financial",
+ "location": "",
+ "message": "Pay City of Austin",
+ "offset_reached": false,
+ "start_time": "2024-12-10 00:00:00",
+ "supported_features": 3
+ },
+ "context": {
+ "id": "01JE47E93S3SF2FHVVR697TK1B",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "calendar.financial",
+ "last_changed": "2024-12-02T00:12:09.634079+00:00",
+ "last_reported": "2024-12-02T17:42:09.785926+00:00",
+ "last_updated": "2024-12-02T17:42:09.785926+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "all_day": true,
+ "description": "Observance\nTo hide observances, go to Google Calendar Settings > Holidays in United States",
+ "end_time": "2024-12-25 00:00:00",
+ "friendly_name": "Holidays in united states",
+ "location": "",
+ "message": "Christmas Eve",
+ "offset_reached": false,
+ "start_time": "2024-12-24 00:00:00"
+ },
+ "context": {
+ "id": "01JDXTF4R23QGNHA7E6Z9AXVDX",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "calendar.holidays_in_united_states",
+ "last_changed": "2024-11-30T06:00:00.002442+00:00",
+ "last_reported": "2024-11-30T06:00:00.002442+00:00",
+ "last_updated": "2024-11-30T06:00:00.002442+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "all_day": true,
+ "description": "Tony Ca is in New York, NY from Dec 22, 2024 to Jan 2, 2025\nView and/or edit details in TripIt : https://www.tripit.com/trip/show?id=356652638\nTripIt - organize your travel at https://www.tripit.com\n",
+ "end_time": "2025-01-03 00:00:00",
+ "friendly_name": "Tony ca (tripit)",
+ "location": "New York, NY",
+ "message": "New York, NY, December 2024",
+ "offset_reached": false,
+ "start_time": "2024-12-22 00:00:00"
+ },
+ "context": {
+ "id": "01JDJQTHG7Q30JQXFASHBGPV7B",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "calendar.tony_ca_tripit",
+ "last_changed": "2024-11-25T22:42:08.330730+00:00",
+ "last_reported": "2024-11-25T22:42:09.031817+00:00",
+ "last_updated": "2024-11-25T22:42:09.031817+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "all_day": true,
+ "description": "This is Debbie Mawad's birthday!",
+ "end_time": "2025-03-09 00:00:00",
+ "friendly_name": "Birthdays",
+ "location": "",
+ "message": "Debbie Mawad's birthday",
+ "offset_reached": false,
+ "start_time": "2025-03-08 00:00:00"
+ },
+ "context": {
+ "id": "01JDJQTJ3KD7FSXAHTRCYX1J0E",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "calendar.birthdays_2",
+ "last_changed": "2024-11-25T22:42:08.330943+00:00",
+ "last_reported": "2024-11-25T22:42:09.651120+00:00",
+ "last_updated": "2024-11-25T22:42:09.651120+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "all_day": false,
+ "description": "",
+ "end_time": "2024-12-03 20:30:00",
+ "friendly_name": "Cassandra shared",
+ "location": "",
+ "message": "Garbage Night (no recyclables)",
+ "offset_reached": false,
+ "start_time": "2024-12-03 20:00:00",
+ "supported_features": 3
+ },
+ "context": {
+ "id": "01JE2AQBJW57VHFJV24H6PY661",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "calendar.cassandra_shared",
+ "last_changed": "2024-12-02T00:01:04.092911+00:00",
+ "last_reported": "2024-12-02T00:01:04.092911+00:00",
+ "last_updated": "2024-12-02T00:01:04.092911+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "all_day": true,
+ "description": "",
+ "end_time": "2024-12-11 00:00:00",
+ "friendly_name": "Birthdays",
+ "location": "",
+ "message": "Birthday: Robert Mawad",
+ "offset_reached": false,
+ "start_time": "2024-12-10 00:00:00",
+ "supported_features": 3
+ },
+ "context": {
+ "id": "01JDTM5JKMJ6MD2FB9SDRRHC72",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "calendar.birthdays",
+ "last_changed": "2024-11-29T00:12:11.764661+00:00",
+ "last_reported": "2024-11-29T16:42:12.120614+00:00",
+ "last_updated": "2024-11-29T00:12:11.764661+00:00",
+ "state": "off"
+ },
+ {
+ "attributes": {
+ "device_class": "timestamp",
+ "friendly_name": "Shared Mail",
+ "icon": "mdi:email"
+ },
+ "context": {
+ "id": "01JDJQTGWZCY2AXF2MPFHR7AJX",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.shared_cassandra_gmail_com_vacation_end_date",
+ "last_changed": "2024-11-25T22:42:08.415909+00:00",
+ "last_reported": "2024-11-25T22:42:08.415909+00:00",
+ "last_updated": "2024-11-25T22:42:08.415909+00:00",
+ "state": "unknown"
+ },
+ {
+ "attributes": {
+ "friendly_name": "Disk Status - Bordeaux",
+ "icon": "mdi:harddisk"
+ },
+ "context": {
+ "id": "01JDJQTGY5P4RYPAV6VEVPNQSS",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.disk_status_bordeaux",
+ "last_changed": "2024-11-25T22:42:08.453352+00:00",
+ "last_reported": "2024-11-25T22:42:08.453352+00:00",
+ "last_updated": "2024-11-25T22:42:08.453352+00:00",
+ "state": "RAID_OK"
+ },
+ {
+ "attributes": {
+ "friendly_name": "Disk Status - Groovy",
+ "icon": "mdi:harddisk"
+ },
+ "context": {
+ "id": "01JE10EH3EK4VGWE4VX4SJZ7DE",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.disk_status_groovy",
+ "last_changed": "2024-12-01T11:42:14.638032+00:00",
+ "last_reported": "2024-12-01T11:42:14.638032+00:00",
+ "last_updated": "2024-12-01T11:42:14.638032+00:00",
+ "state": "RAID_OK"
+ },
+ {
+ "attributes": {
+ "friendly_name": "Disk Status - Cassandra",
+ "icon": "mdi:harddisk"
+ },
+ "context": {
+ "id": "01JDJQTJ3QJ6SQRBWS0SXQ082D",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.disk_status_cassandra",
+ "last_changed": "2024-11-25T22:42:09.655124+00:00",
+ "last_reported": "2024-11-25T22:42:09.655124+00:00",
+ "last_updated": "2024-11-25T22:42:09.655124+00:00",
+ "state": "RAID_OK"
+ },
+ {
+ "attributes": {
+ "current_temperature": 74,
+ "fan_mode": "off",
+ "fan_modes": [
+ "on",
+ "off"
+ ],
+ "friendly_name": "Hallway",
+ "hvac_action": "idle",
+ "hvac_modes": [
+ "heat",
+ "cool",
+ "heat_cool",
+ "off"
+ ],
+ "max_temp": 90,
+ "min_temp": 50,
+ "preset_mode": "none",
+ "preset_modes": [
+ "none",
+ "eco"
+ ],
+ "supported_features": 411,
+ "target_temp_high": 77,
+ "target_temp_low": 72,
+ "temperature": null
+ },
+ "context": {
+ "id": "01JE58XQR0GX63BK9DAVSKQCBX",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "climate.hallway",
+ "last_changed": "2024-11-25T22:42:10.325431+00:00",
+ "last_reported": "2024-12-03T03:27:19.296902+00:00",
+ "last_updated": "2024-12-03T03:27:19.296902+00:00",
+ "state": "heat_cool"
+ },
+ {
+ "attributes": {
+ "device_class": "temperature",
+ "friendly_name": "Hallway Temperature",
+ "state_class": "measurement",
+ "unit_of_measurement": "\u00b0F"
+ },
+ "context": {
+ "id": "01JE58XQR194Z5XTQMY59NDYH8",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.hallway_temperature",
+ "last_changed": "2024-12-03T03:27:19.297458+00:00",
+ "last_reported": "2024-12-03T03:27:19.297458+00:00",
+ "last_updated": "2024-12-03T03:27:19.297458+00:00",
+ "state": "74.3"
+ },
+ {
+ "attributes": {
+ "device_class": "humidity",
+ "friendly_name": "Hallway Humidity",
+ "state_class": "measurement",
+ "unit_of_measurement": "%"
+ },
+ "context": {
+ "id": "01JE4A9D7WT5EG5NCYP9R3MYN6",
+ "parent_id": null,
+ "user_id": null
+ },
+ "entity_id": "sensor.hallway_humidity",
+ "last_changed": "2024-12-02T18:31:55.900614+00:00",
+ "last_reported": "2024-12-02T18:31:55.900614+00:00",
+ "last_updated": "2024-12-02T18:31:55.900614+00:00",
+ "state": "45"
+ }
+]
\ No newline at end of file
diff --git a/src/hi/services/hass/tests/test_hass_converter_mapping.py b/src/hi/services/hass/tests/test_hass_converter_mapping.py
new file mode 100644
index 00000000..fe76616c
--- /dev/null
+++ b/src/hi/services/hass/tests/test_hass_converter_mapping.py
@@ -0,0 +1,270 @@
+import json
+import os
+from django.test import TestCase
+from unittest.mock import patch, MagicMock
+
+from hi.apps.entity.enums import EntityStateType
+from hi.apps.entity.models import Entity
+from hi.integrations.transient_models import IntegrationKey
+from hi.services.hass.hass_converter import HassConverter
+from hi.services.hass.hass_models import HassApi
+
+
+class TestHassConverterMapping(TestCase):
+ """
+ Test the new mapping-based converter methods using real HA API data
+ """
+
+ @classmethod
+ def setUpClass(cls):
+ super().setUpClass()
+ # Load the real HA states data
+ test_data_path = os.path.join(os.path.dirname(__file__), 'data', 'hass-states.json')
+ with open(test_data_path, 'r') as f:
+ cls.real_ha_states_data = json.load(f)
+
+ def setUp(self):
+ # Create a mock entity for testing
+ self.mock_entity = MagicMock(spec=Entity)
+ self.mock_entity.name = "Test Entity"
+
+ def test_determine_entity_state_type_from_mapping_light_dimmer(self):
+ """Test that dimmer lights are correctly identified"""
+
+ # Find a real dimmer light from the test data
+ dimmer_data = None
+ for state_data in self.real_ha_states_data:
+ if ( state_data.get('entity_id', '').startswith('light.switchlinc_dimmer')
+ or state_data.get('entity_id', '').startswith('light.keypadlinc_dimmer') ):
+ dimmer_data = state_data
+ break
+
+ self.assertIsNotNone(dimmer_data, "Should find a dimmer light in test data")
+
+ # Create HassState from real data
+ hass_state = HassConverter.create_hass_state(dimmer_data)
+
+ # Test the mapping
+ entity_state_type = HassConverter._determine_entity_state_type_from_mapping(hass_state)
+
+ # Should be LIGHT_DIMMER if it has brightness capability
+ if 'brightness' in dimmer_data.get('attributes', {}):
+ self.assertEqual(entity_state_type, EntityStateType.LIGHT_DIMMER)
+ else:
+ # Fallback to ON_OFF if no brightness detected
+ self.assertEqual(entity_state_type, EntityStateType.ON_OFF)
+
+ def test_determine_entity_state_type_from_mapping_light_onoff(self):
+ """Test that regular (non-dimmer) lights are correctly identified"""
+
+ # Find a regular relay light from the test data
+ relay_data = None
+ for state_data in self.real_ha_states_data:
+ if ( state_data.get('entity_id', '').startswith('light.switchlinc_relay')
+ and state_data.get('attributes', {}).get('color_mode') == 'onoff' ):
+ relay_data = state_data
+ break
+
+ self.assertIsNotNone(relay_data, "Should find a relay light in test data")
+
+ # Create HassState from real data
+ hass_state = HassConverter.create_hass_state(relay_data)
+
+ # Test the mapping
+ entity_state_type = HassConverter._determine_entity_state_type_from_mapping(hass_state)
+
+ # Should be ON_OFF for relay lights
+ self.assertEqual(entity_state_type, EntityStateType.ON_OFF)
+
+ def test_determine_entity_state_type_from_mapping_switch(self):
+ """Test that switches are correctly identified"""
+
+ # Find a switch from the test data
+ switch_data = None
+ for state_data in self.real_ha_states_data:
+ if state_data.get('entity_id', '').startswith('switch.'):
+ switch_data = state_data
+ break
+
+ self.assertIsNotNone(switch_data, "Should find a switch in test data")
+
+ # Create HassState from real data
+ hass_state = HassConverter.create_hass_state(switch_data)
+
+ # Test the mapping
+ entity_state_type = HassConverter._determine_entity_state_type_from_mapping(hass_state)
+
+ # Should be ON_OFF for switches
+ self.assertEqual(entity_state_type, EntityStateType.ON_OFF)
+
+ def test_determine_entity_state_type_from_mapping_binary_sensor(self):
+ """Test that binary sensors are correctly identified"""
+
+ # Find a binary sensor from the test data
+ binary_sensor_data = None
+ for state_data in self.real_ha_states_data:
+ if state_data.get('entity_id', '').startswith('binary_sensor.'):
+ binary_sensor_data = state_data
+ break
+
+ self.assertIsNotNone(binary_sensor_data, "Should find a binary sensor in test data")
+
+ # Create HassState from real data
+ hass_state = HassConverter.create_hass_state(binary_sensor_data)
+
+ # Test the mapping
+ entity_state_type = HassConverter._determine_entity_state_type_from_mapping(hass_state)
+
+ # Should be appropriate sensor type based on device class
+ device_class = hass_state.device_class
+ if device_class == HassApi.MOTION_DEVICE_CLASS:
+ self.assertEqual(entity_state_type, EntityStateType.MOVEMENT)
+ elif device_class == HassApi.CONNECTIVITY_DEVICE_CLASS:
+ self.assertEqual(entity_state_type, EntityStateType.CONNECTIVITY)
+ else:
+ # Default for binary sensors
+ self.assertEqual(entity_state_type, EntityStateType.ON_OFF)
+
+ def test_has_brightness_capability(self):
+ """Test brightness detection for lights"""
+
+ # Test with a known dimmer light
+ dimmer_data = None
+ for state_data in self.real_ha_states_data:
+ if ( state_data.get('entity_id', '').startswith('light.')
+ and 'brightness' in state_data.get('attributes', {}) ):
+ dimmer_data = state_data
+ break
+
+ if dimmer_data:
+ hass_state = HassConverter.create_hass_state(dimmer_data)
+ has_brightness = HassConverter._has_brightness_capability(hass_state)
+ self.assertTrue(has_brightness, "Should detect brightness capability")
+
+ # Test with a regular light
+ relay_data = None
+ for state_data in self.real_ha_states_data:
+ if ( state_data.get('entity_id', '').startswith('light.')
+ and state_data.get('attributes', {}).get('color_mode') == 'onoff' ):
+ relay_data = state_data
+ break
+
+ if relay_data:
+ hass_state = HassConverter.create_hass_state(relay_data)
+ has_brightness = HassConverter._has_brightness_capability(hass_state)
+ self.assertFalse(has_brightness, "Should not detect brightness capability for relay lights")
+
+ def test_is_controllable_domain_and_type(self):
+ """Test controllability detection"""
+
+ # Test controllable combinations
+ self.assertTrue(
+ HassConverter._is_controllable_domain_and_type( HassApi.LIGHT_DOMAIN,
+ EntityStateType.ON_OFF )
+ )
+ self.assertTrue(
+ HassConverter._is_controllable_domain_and_type( HassApi.LIGHT_DOMAIN,
+ EntityStateType.LIGHT_DIMMER )
+ )
+ self.assertTrue(
+ HassConverter._is_controllable_domain_and_type( HassApi.SWITCH_DOMAIN,
+ EntityStateType.ON_OFF )
+ )
+
+ # Test non-controllable combinations
+ self.assertFalse(
+ HassConverter._is_controllable_domain_and_type( HassApi.SENSOR_DOMAIN,
+ EntityStateType.TEMPERATURE )
+ )
+ self.assertFalse(
+ HassConverter._is_controllable_domain_and_type( HassApi.BINARY_SENSOR_DOMAIN,
+ EntityStateType.MOVEMENT )
+ )
+
+ @patch('hi.apps.model_helper.HiModelHelper.create_on_off_controller')
+ @patch('hi.apps.model_helper.HiModelHelper.create_light_dimmer_controller')
+ @patch('hi.apps.model_helper.HiModelHelper.create_blob_sensor')
+ def test_create_hass_state_with_mapping_integration( self,
+ mock_blob_sensor,
+ mock_light_dimmer_controller,
+ mock_on_off_controller ):
+ """Test the complete integration of the new mapping method"""
+
+ # Mock the return values
+ mock_controller = MagicMock()
+ mock_controller.integration_metadata = {}
+ mock_controller.entity_state = MagicMock()
+ mock_on_off_controller.return_value = mock_controller
+ mock_light_dimmer_controller.return_value = mock_controller
+
+ mock_sensor = MagicMock()
+ mock_sensor.integration_metadata = {}
+ mock_sensor.entity_state = MagicMock()
+ mock_blob_sensor.return_value = mock_sensor
+
+ # Test with a controllable light
+ light_data = None
+ for state_data in self.real_ha_states_data:
+ if state_data.get('entity_id', '').startswith('light.'):
+ light_data = state_data
+ break
+
+ if light_data:
+ hass_state = HassConverter.create_hass_state(light_data)
+ integration_key = IntegrationKey(
+ integration_id='hass',
+ integration_name=hass_state.entity_id
+ )
+
+ # Call the new method
+ entity_state = HassConverter._create_hass_state_with_mapping(
+ hass_device=MagicMock(),
+ hass_state=hass_state,
+ entity=self.mock_entity,
+ integration_key=integration_key,
+ add_alarm_events=False
+ )
+
+ # Should have created a controller and stored metadata
+ self.assertIsNotNone(entity_state)
+
+ # Check that metadata was stored (either controller or sensor should have been called)
+ metadata_stored = (mock_controller.integration_metadata or mock_sensor.integration_metadata)
+ self.assertIsNotNone(metadata_stored)
+
+ # Metadata should contain domain info
+ if mock_controller.integration_metadata:
+ self.assertIn('domain', mock_controller.integration_metadata)
+ self.assertEqual(mock_controller.integration_metadata['domain'], HassApi.LIGHT_DOMAIN)
+
+ def test_domain_parsing_consistency(self):
+ """Test that domain parsing is consistent across all real entities"""
+
+ for state_data in self.real_ha_states_data[:10]: # Test first 10 entities
+ entity_id = state_data.get('entity_id', '')
+ if '.' in entity_id:
+ expected_domain = entity_id.split('.', 1)[0]
+
+ # Create HassState and check domain
+ hass_state = HassConverter.create_hass_state(state_data)
+
+ self.assertEqual(hass_state.domain, expected_domain,
+ f"Domain parsing failed for {entity_id}")
+
+ # Should also have a mapping for this domain (or fallback to BLOB)
+ entity_state_type = HassConverter._determine_entity_state_type_from_mapping(hass_state)
+ self.assertIsNotNone(entity_state_type,
+ f"Should have EntityStateType mapping for domain {expected_domain}")
+
+ def test_service_mapping_completeness(self):
+ """Test that all controllable domains have service mappings"""
+
+ controllable_domains = HassConverter.ALL_CONTROLLABLE_DOMAINS
+
+ for domain in controllable_domains:
+ # Each controllable domain should have at least one service mapping
+ has_mapping = any(
+ key[0] == domain
+ for key in HassConverter.CONTROL_SERVICE_MAPPING.keys()
+ )
+ self.assertTrue(has_mapping, f"Domain {domain} should have service mappings")
diff --git a/src/hi/services/zoneminder/zm_controller.py b/src/hi/services/zoneminder/zm_controller.py
index fcd5c171..eb251acf 100644
--- a/src/hi/services/zoneminder/zm_controller.py
+++ b/src/hi/services/zoneminder/zm_controller.py
@@ -2,7 +2,7 @@ import logging
import re
from hi.integrations.integration_controller import IntegrationController
-from hi.integrations.integration_key import IntegrationKey
+from hi.integrations.transient_models import IntegrationDetails
from hi.integrations.transient_models import IntegrationControlResult
from .zm_mixins import ZoneMinderMixin
@@ -13,9 +13,10 @@ logger = logging.getLogger(__name__)
class ZoneMinderController( IntegrationController, ZoneMinderMixin ):
def do_control( self,
- integration_key : IntegrationKey,
- control_value : str ) -> IntegrationControlResult:
+ integration_details : IntegrationDetails,
+ control_value : str ) -> IntegrationControlResult:
zm_manager = self.zm_manager()
+ integration_key = integration_details.key
try:
if integration_key.integration_name == zm_manager.ZM_RUN_STATE_SENSOR_INTEGRATION_NAME:
return self.set_run_state( run_state_value = control_value )
diff --git a/src/hi/services/zoneminder/zm_manager.py b/src/hi/services/zoneminder/zm_manager.py
index 69e4c209..f19d1d66 100644
--- a/src/hi/services/zoneminder/zm_manager.py
+++ b/src/hi/services/zoneminder/zm_manager.py
@@ -12,7 +12,7 @@ from hi.apps.common.singleton import Singleton
from hi.apps.common.utils import str_to_bool
from hi.integrations.exceptions import IntegrationAttributeError, IntegrationError
-from hi.integrations.integration_key import IntegrationKey
+from hi.integrations.transient_models import IntegrationKey
from hi.integrations.models import Integration, IntegrationAttribute
from .enums import ZmAttributeType
diff --git a/src/hi/services/zoneminder/zm_sync.py b/src/hi/services/zoneminder/zm_sync.py
index 486327fd..835f90f7 100644
--- a/src/hi/services/zoneminder/zm_sync.py
+++ b/src/hi/services/zoneminder/zm_sync.py
@@ -12,7 +12,7 @@ from hi.apps.sense.models import Sensor
from hi.apps.model_helper import HiModelHelper
-from hi.integrations.integration_key import IntegrationKey
+from hi.integrations.transient_models import IntegrationKey
from .zm_metadata import ZmMetaData
from .zm_mixins import ZoneMinderMixin
diff --git a/src/hi/settings/development.py b/src/hi/settings/development.py
index 51e191a2..9adaf81b 100644
--- a/src/hi/settings/development.py
+++ b/src/hi/settings/development.py
@@ -67,7 +67,7 @@ LOGGING = {
},
'hi.apps.alert': {
'handlers': ['console' ],
- 'level': 'DEBUG',
+ 'level': 'INFO',
'propagate': False,
},
'hi.apps.control': {
@@ -107,7 +107,7 @@ LOGGING = {
},
'hi.services.hass': {
'handlers': ['console' ],
- 'level': 'INFO',
+ 'level': 'DEBUG',
'propagate': False,
},
'hi.services.zoneminder': {
diff --git a/src/hi/static/css/main.css b/src/hi/static/css/main.css
index d740d480..87d108e6 100644
--- a/src/hi/static/css/main.css
+++ b/src/hi/static/css/main.css
@@ -385,7 +385,7 @@ input[type="password"],
text-align: center;
font-size: 2rem;
font-weight: bold;
- color: #fff12e;
+ color: var(--warning-color);
background-color: #282425;
border-radius: 0.8rem;
border: 0.1rem solid #282425;
@@ -399,7 +399,7 @@ input[type="password"],
height: 14rem;
color: #282425;
font-size: 4rem;
- background-color: #fff12e;
+ background-color: var(--warning-color);
border-bottom-left-radius: 0.8rem;
border-bottom-right-radius: 0.8rem;
text-align: center;