... "new state": True},
... {"target": "Test State 1", "command": "set state",
... "new state": False},
- ... {"target": "Test AndState", "command": "get state"}]))
+ ... {"target": "Test AndState", "command": "get state"},
+ ... {"target": "Test AndState", "command": "get sources"}]))
... # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
test(): {'sender': '', 'event': 'registered', ...
test(): {'sender': 'test()', 'target': 'Test State 1',
test(): {'sender': 'test()', 'target': 'Test AndState',
'command': 'get state'}
test(): {'sender': 'Test AndState', 'state': False}
+ test(): {'sender': 'test()', 'target': 'Test AndState',
+ 'command': 'get sources'}
+ test(): {'sender': 'Test AndState',
+ 'states': ['Test State 1', 'Test State 2']}
"""
CONF_SCHEMA = {'properties': {'states': {'type': 'array',
self.bus.register(self.name, 'AndState',
[MessageTemplate({'event': {'const': 'changed'},
'state': {'type': 'boolean'}}),
- MessageTemplate({'state': {'type': 'boolean'}})],
+ MessageTemplate({'state': {'type': 'boolean'}}),
+ MessageTemplate({'states': {'type': 'array',
+ 'items': {
+ 'type': 'string'
+ }}})],
[([MessageTemplate({'target':
{'const': self.name},
'command':
{'const': 'get state'}})],
self._get_state),
+ ([MessageTemplate({'target':
+ {'const': self.name},
+ 'command':
+ {'const': 'get sources'}})],
+ self._get_sources),
(updates, self._update)])
async def _get_state(self, message: Message) -> None:
await self.bus.send(Message(self.name, {'state': self.state}))
+ async def _get_sources(self, message: Message) -> None:
+ source_states = list(self.states.keys())
+ await self.bus.send(Message(self.name, {'states': source_states}))
+
async def _update(self, message: Message) -> None:
assert isinstance(message['sender'], str)
assert isinstance(message['state'], bool)
... "new state": True},
... {"target": "Test State 1", "command": "set state",
... "new state": False},
- ... {"target": "Test OrState", "command": "get state"}]))
+ ... {"target": "Test OrState", "command": "get state"},
+ ... {"target": "Test OrState", "command": "get sources"}]))
... # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
test(): {'sender': '', 'event': 'registered', ...
test(): {'sender': 'test()', 'target': 'Test State 1',
test(): {'sender': 'test()', 'target': 'Test OrState',
'command': 'get state'}
test(): {'sender': 'Test OrState', 'state': True}
+ test(): {'sender': 'test()', 'target': 'Test OrState',
+ 'command': 'get sources'}
+ test(): {'sender': 'Test OrState',
+ 'states': ['Test State 1', 'Test State 2']}
"""
CONF_SCHEMA = {'properties': {'states': {'type': 'array',
self.bus.register(self.name, 'OrState',
[MessageTemplate({'event': {'const': 'changed'},
'state': {'type': 'boolean'}}),
- MessageTemplate({'state': {'type': 'boolean'}})],
+ MessageTemplate({'state': {'type': 'boolean'}}),
+ MessageTemplate({'states': {'type': 'array',
+ 'items': {
+ 'type': 'string'
+ }}})],
[([MessageTemplate({'target':
{'const': self.name},
'command':
{'const': 'get state'}})],
self._get_state),
+ ([MessageTemplate({'target':
+ {'const': self.name},
+ 'command':
+ {'const': 'get sources'}})],
+ self._get_sources),
(updates, self._update)])
async def _get_state(self, message: Message) -> None:
await self.bus.send(Message(self.name, {'state': self.state}))
+ async def _get_sources(self, message: Message) -> None:
+ source_states = list(self.states.keys())
+ await self.bus.send(Message(self.name, {'states': source_states}))
+
async def _update(self, message: Message) -> None:
assert isinstance(message['sender'], str)
assert isinstance(message['state'], bool)
... {"target": "Test AndSet", "command": "get state"},
... {"target": "Test State 1", "command": "set state",
... "new state": False},
- ... {"target": "Test AndSet", "command": "get state"}]))
+ ... {"target": "Test AndSet", "command": "get state"},
+ ... {"target": "Test AndSet", "command": "get sources"}]))
... # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
test(): {'sender': '', 'event': 'registered', ...
test(): {'sender': 'test()', 'target': 'Test State 1',
test(): {'sender': 'Test AndSet', 'target': 'Test State 3',
'command': 'set state', 'new state': False}
test(): {'sender': 'Test State 3', 'state': False}
+ test(): {'sender': 'test()', 'target': 'Test AndSet',
+ 'command': 'get sources'}
+ test(): {'sender': 'Test AndSet',
+ 'states': ['Test State 1', 'Test State 2']}
"""
CONF_SCHEMA = {'properties': {'input states': {'type': 'array',
'command':
{'const': 'set state'},
'new state':
- {'type': 'boolean'}})],
+ {'type': 'boolean'}}),
+ MessageTemplate({'states': {'type': 'array',
+ 'items': {
+ 'type': 'string'
+ }}})],
[([MessageTemplate({'target':
{'const': self.name},
'command':
{'const': 'get state'}})],
self._get_state),
+ ([MessageTemplate({'target':
+ {'const': self.name},
+ 'command':
+ {'const': 'get sources'}})],
+ self._get_sources),
(updates, self._update)])
async def _get_state(self, message: Message) -> None:
'command': 'set state',
'new state': self.state}))
+ async def _get_sources(self, message: Message) -> None:
+ source_states = list(self.states.keys())
+ await self.bus.send(Message(self.name, {'states': source_states}))
+
async def _update(self, message: Message) -> None:
assert isinstance(message['sender'], str)
assert isinstance(message['state'], bool)
... {"target": "Test State 2", "command": "set state",
... "new state": True},
... {"target": "Test State 1", "command": "set state",
- ... "new state": False}]))
+ ... "new state": False},
+ ... {"target": "Test OrSet", "command": "get sources"}]))
... # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
test(): {'sender': '', 'event': 'registered', ...
test(): {'sender': 'test()', 'target': 'Test State 1',
test(): {'sender': 'test()', 'target': 'Test State 1',
'command': 'set state', 'new state': False}
test(): {'sender': 'Test State 1', 'event': 'changed', 'state': False}
+ test(): {'sender': 'test()', 'target': 'Test OrSet',
+ 'command': 'get sources'}
+ test(): {'sender': 'Test OrSet',
+ 'states': ['Test State 1', 'Test State 2']}
"""
CONF_SCHEMA = {'properties': {'input states': {'type': 'array',
'command':
{'const': 'set state'},
'new state':
- {'type': 'boolean'}})],
+ {'type': 'boolean'}}),
+ MessageTemplate({'states': {'type': 'array',
+ 'items': {
+ 'type': 'string'
+ }}})],
[([MessageTemplate({'target':
{'const': self.name},
'command':
{'const': 'get state'}})],
self._get_state),
+ ([MessageTemplate({'target':
+ {'const': self.name},
+ 'command':
+ {'const': 'get sources'}})],
+ self._get_sources),
(updates, self._update)])
async def _get_state(self, message: Message) -> None:
'command': 'set state',
'new state': self.state}))
+ async def _get_sources(self, message: Message) -> None:
+ source_states = list(self.states.keys())
+ await self.bus.send(Message(self.name, {'states': source_states}))
+
async def _update(self, message: Message) -> None:
assert isinstance(message['sender'], str)
assert isinstance(message['state'], bool)