Nyx Node
Toggle main menu visibility
Loading...
Searching...
No Matches
indi_light.py
1
# -*- coding: utf-8 -*-
2
########################################################################################################################
3
# NyxNode
4
# Author: Jérôme ODIER <jerome.odier@lpsc.in2p3.fr>
5
# SPDX-License-Identifier: GPL-3.0+
6
########################################################################################################################
7
8
import
typing
9
10
########################################################################################################################
11
12
from
..
import
obj
13
from
..
import
bind
14
from
..
import
json
15
16
from
.
import
enums
17
from
.
import
utils
18
19
########################################################################################################################
20
21
## @defgroup LIGHT_MESSAGE_PY Nyx Light Message
22
# @brief Nyx / INDI Light Message.
23
24
########################################################################################################################
25
26
@utils.nyx_property
(
27
'name'
,
28
'@name'
,
29
)
30
@utils.nyx_property
(
31
'label'
,
32
'@label'
,
33
)
34
@utils.nyx_property
(
35
'value'
,
36
'$'
,
37
kind = enums.NyxState,
38
getter = enums.NyxState.to_int,
39
setter = enums.NyxState.to_str,
40
)
41
class
NyxLightProp
(
json.json_dict.NyxDict
):
42
"""!
43
@ingroup LIGHT_MESSAGE_PY
44
@brief INDI / Nyx light property.
45
"""
46
47
####################################################################################################################
48
49
def
__init__
(self, name: str, label: str |
None
=
None
, value:
enums.NyxState
| int | str = enums.NyxState.IDLE):
50
"""!
51
@brief Allocates a new INDI / Nyx light property.
52
53
@param name Property name.
54
@param label Property label.
55
@param value Initial value.
56
"""
57
58
super().
__init__
(bind.lib.nyx_light_prop_new(
59
bind.as_bytes(name, allow_none =
False
),
60
bind.as_bytes(label, allow_none =
True
),
61
enums.NyxState.to_int(value),
62
))
63
64
####################################################################################################################
65
66
@obj.nyx_callback(bind.nyx_callback_int_t)
67
def
_nyx_callback_func(self, _vector, _prop, new_value, old_value) -> bool:
68
69
return
all(self.
_dispatch_callbacks
(
70
enums.NyxState.to_int(new_value),
71
enums.NyxState.to_int(old_value),
72
))
73
74
########################################################################################################################
75
76
@utils.nyx_property
(
77
'device'
,
78
'@device'
,
79
)
80
@utils.nyx_property
(
81
'name'
,
82
'@name'
,
83
)
84
@utils.nyx_property
(
85
'state'
,
86
'@state'
,
87
kind =
enums.NyxState
,
88
getter = enums.NyxState.to_int,
89
setter = enums.NyxState.to_str,
90
)
91
class
NyxLightVector
(
json.json_dict.NyxDict
):
92
"""!
93
@ingroup LIGHT_MESSAGE_PY
94
@brief INDI / Nyx light vector.
95
"""
96
97
####################################################################################################################
98
99
def
__init__
(self, device: str, name: str, state:
enums.NyxState
| int | str, props: typing.Iterable[NyxLightProp], **opts: typing.Any):
100
"""!
101
@brief Allocates a new INDI / Nyx light vector.
102
103
@param device Device name.
104
@param name Vector name.
105
@param state Vector state.
106
@param props Properties.
107
@param opts Options (group, label, hints, timeout, message).
108
"""
109
110
################################################################################################################
111
112
super().
__init__
(bind.lib.nyx_light_vector_new(
113
bind.as_bytes(device, allow_none =
False
),
114
bind.as_bytes(name, allow_none =
False
),
115
enums.NyxState.to_int(state),
116
bind.nyx_dict_p(),
117
bind.as_opts(opts),
118
))
119
120
################################################################################################################
121
122
# noinspection PyTypeChecker
123
children:
json.NyxList
= self[
'children'
]
124
125
for
prop
in
props:
126
127
if
not
isinstance(prop, NyxLightProp):
128
129
raise
TypeError(
'Expected NyxLightProp'
)
130
131
children.append(prop)
132
133
####################################################################################################################
134
135
@obj.nyx_callback(bind.nyx_callback_vector_t)
136
def
_nyx_callback_func(self, _vector: json.
json_dict.NyxDict
, modified: bool) ->
None
:
137
138
self.
_dispatch_callbacks
(bool(modified))
139
140
########################################################################################################################
141
142
__all__ = [name
for
name
in
globals()
if
name.lower().startswith(
'nyx'
)]
143
144
########################################################################################################################
nyx.json.json_dict.NyxDict
JSON dict object.
Definition
json_dict.py:22
nyx.json.json_list.NyxList
JSON list object.
Definition
json_list.py:22
nyx.obj.NyxObject._dispatch_callbacks
_dispatch_callbacks(self, *args)
Definition
obj.py:154
nyx.indi.enums.NyxState
Vector state hint.
Definition
enums.py:24
nyx.indi.indi_light.NyxLightProp.__init__
__init__(self, str name, str|None label=None, enums.NyxState|int|str value=enums.NyxState.IDLE)
Allocates a new INDI / Nyx light property.
Definition
indi_light.py:49
nyx.indi.indi_light.NyxLightVector.__init__
__init__(self, str device, str name, enums.NyxState|int|str state, typing.Iterable[NyxLightProp] props, **typing.Any opts)
Allocates a new INDI / Nyx light vector.
Definition
indi_light.py:108
nyx.indi.indi_light.NyxLightProp
INDI / Nyx light property.
Definition
indi_light.py:41
nyx.indi.indi_light.NyxLightVector
INDI / Nyx light vector.
Definition
indi_light.py:100
Author:
Jérôme ODIER
License:
LGPL-3.0-or-later
Copyright:
LPSC / CNRS