-
Notifications
You must be signed in to change notification settings - Fork 161
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 #6 from Emantor/topic/onewire
- Loading branch information
Showing
10 changed files
with
96 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ pytest-isort | |
pytest-mock | ||
pytest-pylint | ||
pytest-runner | ||
onewire | ||
pyudev | ||
yapf | ||
requests |
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,29 @@ | ||
import logging | ||
import onewire | ||
|
||
import attr | ||
|
||
from ..factory import target_factory | ||
from ..resource import OneWirePIO | ||
from ..protocol import DigitalOutputProtocol | ||
from .common import Driver | ||
|
||
@target_factory.reg_driver | ||
@attr.s | ||
class OneWirePIODriver(Driver, DigitalOutputProtocol): | ||
|
||
bindings = {"port": OneWirePIO, } | ||
|
||
def __attrs_post_init__(self): | ||
super().__attrs_post_init__() | ||
self.onewire = onewire.Onewire(self.port.host) | ||
|
||
def set(self, status): | ||
if status == True: | ||
self.onewire.set(self.port.path, '1') | ||
else: | ||
self.onewire.set(self.port.path, '0') | ||
|
||
def get(self): | ||
status = self.onewire.get(self.port.path) | ||
return status == '1' |
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,15 @@ | ||
import abc | ||
|
||
|
||
class DigitalOutputProtocol(abc.ABC): | ||
"""Abstract class providing the OneWireProtocol interface""" | ||
|
||
@abc.abstractmethod | ||
def get(self): | ||
"""Implementations should return the status of the OneWirePort.""" | ||
raise NotImplementedError | ||
|
||
@abc.abstractmethod | ||
def set(self, status): | ||
"""Implementations should set the status of the OneWirePort""" | ||
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from .base import SerialPort | ||
from .serialport import RawSerialPort | ||
from .networkservice import NetworkService | ||
from .onewireport import OneWirePIO | ||
from .power import NetworkPowerPort | ||
from .udev import USBSerialPort | ||
from .common import Resource, ResourceManager, ManagedResource |
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,16 @@ | ||
import attr | ||
|
||
from ..factory import target_factory | ||
from .common import Resource | ||
|
||
|
||
@target_factory.reg_resource | ||
@attr.s | ||
class OneWirePIO(Resource): | ||
"""This resource describes a Onewire PIO Port. | ||
Arguments: | ||
host - The hostname of the owserver e.g. localhost:4304 | ||
path - Path to the port on the owserver e.g. 29.7D6913000000/PIO.0""" | ||
host = attr.ib(validator=attr.validators.instance_of(str)) | ||
path = attr.ib(validator=attr.validators.instance_of(str)) |
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 |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
'pytest', | ||
'pyyaml', | ||
'pyudev', | ||
'onewire', | ||
'requests', | ||
], | ||
packages=[ | ||
|