Skip to content

Commit

Permalink
Avoid excessive switches on startup (#293)
Browse files Browse the repository at this point in the history
* Prevent initial value for relays.

* Changelog: 5.0.2.

* Asserting turned off in constructor test.

* Fix assertion.

* set initial value to `inverted`

* Updating the serialization test.

* Removing assertions since it has to be xorred.

* Update CHANGELOG.md
  • Loading branch information
RobinTail authored Aug 17, 2024
1 parent c4211fd commit d2e2285
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Version 5

### 5.0.2

- Initial state for relays is `OFF` — fixes excessive switches on startup in most cases.

### 5.0.1

- Preventing installations on environments having unsupported Python versions:
Expand Down
2 changes: 1 addition & 1 deletion octoprint_octorelay/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Driver():
def __init__(self, pin: int, inverted: bool, pin_factory=None):
self.pin = pin # GPIO pin
self.inverted = inverted # marks the relay as normally closed
self.handle = LED(pin, pin_factory=pin_factory)
self.handle = LED(pin, pin_factory=pin_factory, initial_value=inverted)

def __repr__(self) -> str:
return f"{type(self).__name__}(pin={self.pin},inverted={self.inverted},closed={self.is_closed()})"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_constructor(self):
def test_serialization(self):
relay = Driver(18, True, MockFactory())
serialization = f"{relay}"
self.assertEqual(serialization, "Driver(pin=18,inverted=True,closed=True)")
self.assertEqual(serialization, "Driver(pin=18,inverted=True,closed=False)")

def test_close(self):
cases = [
Expand Down

0 comments on commit d2e2285

Please sign in to comment.