Skip to content

Commit

Permalink
review docs
Browse files Browse the repository at this point in the history
  • Loading branch information
2bndy5 committed Aug 6, 2024
1 parent de4d2f3 commit 22c4790
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 16 deletions.
26 changes: 15 additions & 11 deletions circuitpython_mocks/digitalio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum, auto

from typing import Union, Optional
from circuitpython_mocks._mixins import ContextManaged, Expecting
from circuitpython_mocks.digitalio.operations import GetState, SetState
from circuitpython_mocks.board import Pin
Expand Down Expand Up @@ -34,13 +34,17 @@ def __init__(self, pin: Pin, **kwargs):
self._pin = pin
self.switch_to_input()

def switch_to_output(self, value=False, drive_mode=DriveMode.PUSH_PULL):
def switch_to_output(
self,
value: Union[bool, int] = False,
drive_mode: DriveMode = DriveMode.PUSH_PULL,
):
"""Switch the Digital Pin Mode to Output"""
self.direction = Direction.OUTPUT
self.value = value
self.drive_mode = drive_mode

def switch_to_input(self, pull=None):
def switch_to_input(self, pull: Optional[Pull] = None):
"""Switch the Digital Pin Mode to Input"""
self.direction = Direction.INPUT
self.pull = pull
Expand All @@ -50,12 +54,12 @@ def deinit(self):
del self._pin

@property
def direction(self):
def direction(self) -> Direction:
"""Get or Set the Digital Pin Direction"""
return self.__direction

@direction.setter
def direction(self, value):
def direction(self, value: Direction):
self.__direction = value
if value == Direction.OUTPUT:
# self.value = False
Expand All @@ -66,7 +70,7 @@ def direction(self, value):
raise AttributeError("Not a Direction")

@property
def value(self):
def value(self) -> Union[bool, int]:
"""The Digital Pin Value.
This property will check against `SetState` and `GetState`
:py:attr:`~circuitpython_mocks._mixins.Expecting.expectations`."""
Expand All @@ -78,7 +82,7 @@ def value(self):
return op.state

@value.setter
def value(self, val):
def value(self, val: Union[bool, int]):
if self.direction != Direction.OUTPUT:
raise AttributeError("Not an output")
assert self.expectations, "No expectations found for DigitalInOut.value.setter"
Expand All @@ -89,25 +93,25 @@ def value(self, val):
op.assert_state(val)

@property
def pull(self):
def pull(self) -> Optional[Pull]:
"""The pin pull direction"""
if self.direction == Direction.INPUT:
return self.__pull
raise AttributeError("Not an input")

@pull.setter
def pull(self, pul):
def pull(self, pul: Optional[Pull]):
if self.direction != Direction.INPUT:
raise AttributeError("Not an input")
self.__pull = pul

@property
def drive_mode(self):
def drive_mode(self) -> DriveMode:
"""The Digital Pin Drive Mode"""
if self.direction != Direction.OUTPUT:
raise AttributeError("Not an output")
return self.__drive_mode

@drive_mode.setter
def drive_mode(self, mod):
def drive_mode(self, mod: DriveMode):
self.__drive_mode = mod
1 change: 0 additions & 1 deletion docs/board.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

.. automodule:: circuitpython_mocks.board
:members:
:undoc-members:

This module includes the following dummy pins for soft-testing:

Expand Down
17 changes: 16 additions & 1 deletion docs/busio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,22 @@
=================

.. automodule:: circuitpython_mocks.busio
:members:

.. autoclass:: circuitpython_mocks.busio.I2C
:members: __init__, readfrom_into, writeto, writeto_then_readfrom, scan
.. autoclass:: circuitpython_mocks.busio.SPI
:members: __init__, readinto, write, write_readinto, configure, frequency
.. autoclass:: circuitpython_mocks.busio.UART
:members: __init__, readinto, readline, write

.. py:class:: circuitpython_mocks.busio.UART.Parity
A mock enumeration of :external:py:class:`busio.Parity`.

.. py:attribute:: ODD
:type: Parity
.. py:attribute:: EVEN
:type: Parity

``busio.operations``
--------------------
Expand Down
7 changes: 6 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
"sphinx.ext.intersphinx",
"sphinx_jinja",
]

autodoc_class_signature = "separated"
autodoc_default_options = {
"exclude-members": "__new__",
}

templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
Expand All @@ -32,7 +36,7 @@
"pins": [
x
for x in dir(circuitpython_mocks.board)
if not x.startswith("_") and x != "Pin"
if not x.startswith("_") and x not in ("Pin", "board_id")
]
}
}
Expand Down Expand Up @@ -63,6 +67,7 @@
"features": [
"navigation.top",
"search.share",
"toc.follow",
],
"palette": [
{
Expand Down
38 changes: 36 additions & 2 deletions docs/digitalio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,44 @@
=================

.. automodule:: circuitpython_mocks.digitalio
:members:

.. autoclass:: circuitpython_mocks.digitalio.DigitalInOut
:members: value, deinit, direction, drive_mode, pull, switch_to_input, switch_to_output

.. py:class:: circuitpython_mocks.digitalio.Direction
A mock enumeration of :external:py:class:`digitalio.Direction`.

.. py:attribute:: INPUT
:type: Direction
.. py:attribute:: OUTPUT
:type: Direction

.. py:class:: circuitpython_mocks.digitalio.DriveMode
A mock enumeration of :external:py:class:`digitalio.DriveMode`.

.. py:attribute:: PUSH_PULL
:type: DriveMode
.. py:attribute:: OPEN_DRAIN
:type: DriveMode

.. py:class:: circuitpython_mocks.digitalio.Pull
A mock enumeration of :external:py:class:`digitalio.Pull`.

.. py:attribute:: UP
:type: Pull
.. py:attribute:: DOWN
:type: Pull


``digitalio.operations``
------------------------

.. automodule:: circuitpython_mocks.digitalio.operations
:members:

.. autoclass:: circuitpython_mocks.digitalio.operations.SetState
:members: __init__
.. autoclass:: circuitpython_mocks.digitalio.operations.GetState
:members: __init__

0 comments on commit 22c4790

Please sign in to comment.