Nyx Node
Toggle main menu visibility
Loading...
Searching...
No Matches
indi_switch.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 SWITCH_MESSAGE_PY Nyx Switch Message
22
# @brief Nyx / INDI Switch 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.NyxOnOff,
38
getter = enums.NyxOnOff.to_int,
39
setter = enums.NyxOnOff.to_str,
40
)
41
class
NyxSwitchProp
(
json.json_dict.NyxDict
):
42
"""!
43
@ingroup SWITCH_MESSAGE_PY
44
@brief INDI / Nyx switch property.
45
"""
46
47
####################################################################################################################
48
49
def
__init__
(self, name: str, label: str |
None
=
None
, value:
enums.NyxOnOff
| int | str | bool = enums.NyxOnOff.OFF):
50
"""!
51
@brief Allocates a new INDI / Nyx switch 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_switch_prop_new(
59
bind.as_bytes(name, allow_none =
False
),
60
bind.as_bytes(label, allow_none =
True
),
61
enums.NyxOnOff.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.NyxOnOff.to_int(new_value),
71
enums.NyxOnOff.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
@utils.nyx_property
(
92
'perm'
,
93
'@perm'
,
94
kind =
enums.NyxPerm
,
95
getter = enums.NyxPerm.to_int,
96
setter = enums.NyxPerm.to_str,
97
)
98
@utils.nyx_property
(
99
'rule'
,
100
'@rule'
,
101
kind =
enums.NyxRule
,
102
getter = enums.NyxRule.nyx_rule_int,
103
setter = enums.NyxRule.nyx_rule_str,
104
)
105
class
NyxSwitchVector
(
json.json_dict.NyxDict
):
106
"""!
107
@ingroup SWITCH_MESSAGE_PY
108
@brief INDI / Nyx switch vector.
109
"""
110
111
####################################################################################################################
112
113
def
__init__
(self, device: str, name: str, state:
enums.NyxState
| int | str, perm:
enums.NyxPerm
| int | str, rule:
enums.NyxRule
| int | str, props: typing.Iterable[NyxSwitchProp], **opts: typing.Any):
114
"""!
115
@brief Allocates a new INDI / Nyx switch vector.
116
117
@param device Device name.
118
@param name Vector name.
119
@param state Vector state.
120
@param perm Vector permissions.
121
@param rule Vector rules.
122
@param props Properties.
123
@param opts Options (group, label, hints, timeout, message).
124
"""
125
126
################################################################################################################
127
128
super().
__init__
(bind.lib.nyx_switch_vector_new(
129
bind.as_bytes(device, allow_none =
False
),
130
bind.as_bytes(name, allow_none =
False
),
131
enums.NyxState.to_int(state),
132
enums.NyxPerm.to_int(perm),
133
enums.NyxRule.nyx_rule_int(rule),
134
bind.nyx_dict_p(),
135
bind.as_opts(opts),
136
))
137
138
################################################################################################################
139
140
# noinspection PyTypeChecker
141
children:
json.NyxList
= self[
'children'
]
142
143
for
prop
in
props:
144
145
if
not
isinstance(prop, NyxSwitchProp):
146
147
raise
TypeError(
'Expected NyxSwitchProp'
)
148
149
children.append(prop)
150
151
####################################################################################################################
152
153
@obj.nyx_callback(bind.nyx_callback_vector_t)
154
def
_nyx_callback_func(self, _vector: json.
json_dict.NyxDict
, modified: bool) ->
None
:
155
156
self.
_dispatch_callbacks
(bool(modified))
157
158
########################################################################################################################
159
160
__all__ = [name
for
name
in
globals()
if
name.lower().startswith(
'nyx'
)]
161
162
########################################################################################################################
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.NyxOnOff
Switch state.
Definition
enums.py:189
nyx.indi.enums.NyxPerm
Vector permission hint.
Definition
enums.py:81
nyx.indi.enums.NyxRule
Switch vector rule hint.
Definition
enums.py:135
nyx.indi.enums.NyxState
Vector state hint.
Definition
enums.py:24
nyx.indi.indi_switch.NyxSwitchVector.__init__
__init__(self, str device, str name, enums.NyxState|int|str state, enums.NyxPerm|int|str perm, enums.NyxRule|int|str rule, typing.Iterable[NyxSwitchProp] props, **typing.Any opts)
Allocates a new INDI / Nyx switch vector.
Definition
indi_switch.py:122
nyx.indi.indi_switch.NyxSwitchProp.__init__
__init__(self, str name, str|None label=None, enums.NyxOnOff|int|str|bool value=enums.NyxOnOff.OFF)
Allocates a new INDI / Nyx switch property.
Definition
indi_switch.py:49
nyx.indi.indi_switch.NyxSwitchProp
INDI / Nyx switch property.
Definition
indi_switch.py:41
nyx.indi.indi_switch.NyxSwitchVector
INDI / Nyx switch vector.
Definition
indi_switch.py:114
Author:
Jérôme ODIER
License:
LGPL-3.0-or-later
Copyright:
LPSC / CNRS