File: behavior_instance.py

package info (click to toggle)
python-aiohue 4.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 612 kB
  • sloc: python: 4,444; sh: 30; makefile: 5
file content (132 lines) | stat: -rw-r--r-- 3,925 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
"""
Model(s) for behavior_instance resource on HUE bridge.

API to manage instances of script.
https://developers.meethue.com/develop/hue-api-v2/api-reference/#resource_behavior_instance
"""

from dataclasses import dataclass
from enum import Enum

from .resource import ResourceIdentifier, ResourceTypes


class BehaviorInstanceStatus(Enum):
    """Behavior script instance status."""

    INITIALIZING = "initializing"
    RUNNING = "running"
    DISABLED = "disabled"
    ERRORED = "errored"


@dataclass
class BehaviorInstanceMetadata:
    """Represent BehaviorInstance Metadata object as used by BehaviorInstance resource."""

    name: str | None = None


class DependencyLevel(Enum):
    """
    Enum with dependency Levels.

    - non_critical: Defines a dependency between resources:
      although source is impacted by removal of target, source remains
      of target means removal of source.
    - critical: Defines a critical dependency between resources:
      source cannot function without target,
      hence removal of target means removal of source.
    """

    NON_CRITICAL = "non_critical"
    CRITICAL = "critical"


@dataclass
class ResourceDependee:
    """
    ResourceDependee object as used by the Hue api.

    Represents a resource which (this) resource is dependent on.

    clip-api.schema.json#/definitions/ResourceDependeeGet
    """

    # target: required(object - Id of the dependency resource (target).
    target: ResourceIdentifier
    level: DependencyLevel
    type: str | None = None


@dataclass
class BehaviorInstance:
    """
    Represent a (full) `BehaviorInstance` resource when retrieved from the api.

    BehaviorInstance is an instance of a script.
    https://developers.meethue.com/develop/hue-api-v2/api-reference/#resource_behavior_instance_get
    """

    id: str
    script_id: str
    enabled: bool

    # configuration: required(object)
    # Script configuration.
    # This property is validated using ScriptDefinition.configuration_schema JSON schema.
    configuration: dict

    # dependees: required(array of ResourceDependee)
    # Represents all resources which this instance depends on.
    dependees: list[ResourceDependee]

    # status: required(one of initializing, running, disabled, errored)
    # If the script is in the errored state then check errors for more details about the error.
    status: BehaviorInstanceStatus

    # last_error: required(string) - Last error happened while executing the script.
    last_error: str
    metadata: BehaviorInstanceMetadata

    # state: (object)
    # Script instance state.
    # This read-only property is according to ScriptDefinition.state_schema JSON schema.
    state: dict | None = None

    id_v1: str | None = None
    migrated_from: str | None = None
    type: ResourceTypes = ResourceTypes.BEHAVIOR_INSTANCE


@dataclass
class BehaviorInstancePut:
    """
    Properties to send when updating/setting a `BehaviorInstance` object on the api.

    https://developers.meethue.com/develop/hue-api-v2/api-reference/#resource_behavior_instance__put
    """

    enabled: bool | None = None
    # configuration: (object) Script configuration.
    # This property is validated using ScriptDefinition.configuration_schema JSON schema.
    configuration: dict | None = None
    # trigger: (object) Action that needs to be taken by this script instance.
    # This property is validated using ScriptDefinition.trigger_schema JSON schema.
    trigger: dict | None = None
    metadata: BehaviorInstanceMetadata | None = None


@dataclass
class BehaviorInstancePost:
    """
    Properties to send when creating a `BehaviorInstance` object on the api.

    https://developers.meethue.com/develop/hue-api-v2/api-reference/#behavior_instance_post
    """

    script_id: str
    enabled: bool
    configuration: dict
    metadata: BehaviorInstanceMetadata | None = None
    migrated_from: str | None = None