-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from s-kostyuk/finalized_capabilities
Finalized capabilities (1/n) This pull request finalizes the naming scheme for Capabilities and adds two new important Capabilities to the list: OnOff anf OpenClosed
- Loading branch information
Showing
13 changed files
with
136 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from enum import Enum | ||
|
||
|
||
class IsActive(object): | ||
""" | ||
This interface allows a read-only access to is_active status of a Thing. | ||
This interface must to be provided if only only if the current state of | ||
a Thing can be directly stated as 'active' (i.e. working, acting, turned | ||
on, playing) and 'inactive' (not working, not acting, turned off, stopped). | ||
Otherwise it's not recommended to implement an IsActive interface. | ||
is_active field value if a binary value with True mapped to 'active' and | ||
False mapped to 'inactive'. It's recommended to map uncertain or unknown | ||
(null) state to the 'inactive' (False) value. | ||
The value of is_active field can't be directly changed by user but | ||
Actuators are allowed to provide some additional methods to switch between | ||
'active' and 'inactive' states. Also such Actuators are must to provide | ||
such methods as 'activate', 'deactivate' and 'toggle' to switch between the | ||
opposite states. | ||
Things are must to preserve their last known state even after | ||
they become unavailable. And all client classes must to be ready | ||
to this fact (i.e. analyze a time of the last update in last_updated | ||
property, analyze an availability status in is_available property | ||
and so on). | ||
""" | ||
|
||
@property | ||
def is_active(self) -> bool: | ||
""" | ||
Returns if this object is currently in one of the | ||
'active' states (like 'on' for lighting, 'open' | ||
for a door and 'playing' for player) | ||
:return: True if object is in any of 'active' states, | ||
False otherwise | ||
""" | ||
raise NotImplementedError() |
6 changes: 3 additions & 3 deletions
6
dpl/things/capabilities/i_available.py → dpl/things/capabilities/is_available.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
dpl/things/capabilities/i_enabled.py → dpl/things/capabilities/is_enabled.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
dpl/things/capabilities/i_last_updated.py → dpl/things/capabilities/last_updated.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class OnOff(object): | ||
""" | ||
On/Off devices are devices that can be either powered “on” or “off”. | ||
The current state of those devices can be determined by the value of | ||
the is_power_on field. | ||
Actuator On/Off devices are able to be turned on and off with the on and | ||
off commands correspondingly. Actuator On/Off devices are MUST to provide | ||
``on`` and ``off`` commands. And usually can be toggled between two states | ||
with a ``toggle`` command. | ||
If the device provides both on_off and is_active capabilities, then the | ||
on state is usually mapped to true value of is_active field and off state | ||
is mapped to false. on command is also mapped to the activate and off | ||
command is mapped to the deactivate command. | ||
""" | ||
@property | ||
def is_powered_on(self) -> bool: | ||
""" | ||
Indicates if this device powered on or not | ||
:return: True if this device is powered on, False otherwise. | ||
""" | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from enum import Enum | ||
|
||
from .has_state import HasState | ||
|
||
|
||
class OpenClosed(HasState): | ||
""" | ||
Open/Closed devices are devices that can be in either "open" or | ||
"closed" state. The current state of those devices can be determined bу | ||
the value of the ``state`` field. In addition to the "open" and "closed" | ||
states there are two transitional states possible: "opening" and "closing". | ||
Actuator Open/Closed devices are MUST to implement to ``open`` and | ||
``close`` commands to open or close a Thing correspondingly. | ||
If the device provides both ``open_closed`` and ``is_active`` capabilities, | ||
then the ``open`` and ``opening`` states are usually mapped to ``true`` | ||
value of ``is_active`` field and ``close`` with ``closing`` states are | ||
mapped to ``false``. Also generic ``activate`` and ``deactivate`` commands | ||
are available for such devices with ``activate`` mapped to ``open``, | ||
``deactivate`` mapped to ``close`` and ``toggle`` toggles between the | ||
opposite states (from ``open`` to ``closed``, from ``closed`` to ``open``, | ||
from ``opening`` to ``closed``, from ``closing`` to ``opened``). | ||
""" | ||
class States(Enum): | ||
""" | ||
Possible states of the thing: 'open', 'closed' and 'unknown'. | ||
""" | ||
closed = 0b00 | ||
opening = 0b01 | ||
closing = 0b10 | ||
opened = 0b11 | ||
unknown = None | ||
|
||
# Everything else is inherited from HasState Capability |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters