Leggin / dirigera

This repository provides an unofficial Python client for controlling the IKEA Dirigera Smart Home Hub.
MIT License
99 stars 19 forks source link

Update scene.py #78

Closed slajob closed 2 months ago

slajob commented 2 months ago

Validation error due to typo in trigger field. Traceback below:

2024-05-13 20:53:41.429 ERROR (MainThread) [homeassistant.components.scene] Error while setting up dirigera_platform platform for scene
Traceback (most recent call last):
  File "/workspaces/core/homeassistant/helpers/entity_platform.py", line 351, in _async_setup_platform
    await asyncio.shield(awaitable)
  File "/workspaces/core/config/custom_components/dirigera_platform/scene.py", line 33, in async_setup_entry
    scenes: list[DirigeraScene] = await hass.async_add_executor_job(hub.get_scenes)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vscode/.local/lib/python3.12/site-packages/dirigera/hub/hub.py", line 337, in get_scenes
    return [dict_to_scene(scene, self) for scene in scenes]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vscode/.local/lib/python3.12/site-packages/dirigera/devices/scene.py", line 134, in dict_to_scene
    return Scene(dirigeraClient=dirigera_client, **data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pydantic/main.py", line 339, in __init__
    values, fields_set, validation_error = validate_model(__pydantic_self__.__class__, data)
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pydantic/main.py", line 1076, in validate_model
    v_, errors_ = field.validate(value, values, loc=field.alias, cls=cls_)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pydantic/fields.py", line 895, in validate
    v, errors = self._validate_sequence_like(v, values, loc, cls)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pydantic/fields.py", line 928, in _validate_sequence_like
    r, ee = self._validate_singleton(v_, values, v_loc, cls)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pydantic/fields.py", line 1094, in _validate_singleton
    value, error = field.validate(v, values, loc=loc, cls=cls)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pydantic/fields.py", line 884, in validate
    v, errors = self._validate_singleton(v, values, loc, cls)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pydantic/fields.py", line 1101, in _validate_singleton
    return self._apply_validators(v, values, loc, cls, self.validators)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pydantic/fields.py", line 1157, in _apply_validators
    v = validator(cls, v, values, self, self.model_config)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pydantic/class_validators.py", line 337, in <lambda>
    return lambda cls, v, values, field, config: validator(v)
                                                 ^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pydantic/main.py", line 711, in validate
    return cls(**value)
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pydantic/main.py", line 339, in __init__
    values, fields_set, validation_error = validate_model(__pydantic_self__.__class__, data)
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pydantic/main.py", line 1076, in validate_model
    v_, errors_ = field.validate(value, values, loc=field.alias, cls=cls_)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pydantic/fields.py", line 860, in validate
    raise ConfigError(
pydantic.errors.ConfigError: field "trigger" not yet prepared so type is still a ForwardRef, you might need to call Trigger.update_forward_refs().
Leggin commented 2 months ago

Are you sure? when I log the output of a tescene I get this:

{
        "id": "168057f6-f903-44d0-91df-186d530c304e",
        "info": {
            "name": "Test",
            "icon": "scenes_clean_sparkles"
        },
        "type": "userScene",
        "triggers": [
            {
                "id": "ec33789b-613e-4885-8dcf-0af8ce1d2ef6",
                "type": "app",
                "triggeredAt": "2024-05-14T05:39:42.376Z",
                "disabled": false
            },
            {
                "id": "63dd5d9e-a47c-48f0-afc7-09ec6a743e64",
                "type": "time",
                "disabled": false,
                "trigger": {       // here it is only trigger
                    "days": [
                        "Sun",
                        "Thu",
                        "Sat",
                        "Wed",
                        "Mon",
                        "Fri",
                        "Tue"
                    ],
                    "time": "07:39"
                },
                "nextTriggerAt": "2024-05-15T05:39:00.000Z"
            }
        ],
        "actions": [
            {
                "id": "102102b0-54ff-45a2-a272-706499b2b776_1",
                "type": "device",
                "deviceId": "102102b0-54ff-45a2-a272-706499b2b776_1",
                "enabled": true,
                "attributes": {
                    "isOn": true,
                    "lightLevel": 100
                }
            }
        ],
        "commands": [],
        "createdAt": "2024-05-14T05:39:14.300Z",
        "lastCompleted": "2024-05-14T05:39:41.460Z",
        "lastTriggered": "2024-05-14T05:39:41.460Z",
        "undoAllowedDuration": 30,
        "lastUndo": "2024-05-14T05:39:42.384Z"
    }
slajob commented 2 months ago

You are right. It should be repaired by home assistant component side. Closing PR