Skip to content

Commit

Permalink
Releasing 2.0.1 (#88)
Browse files Browse the repository at this point in the history
* Fixes for non-inverted relay (#48)

* fixed for non-inverted relay

- I created a new turn_on_pin function and called that function when print_started.
- It also executes "OS Command ON" now

---------

Co-authored-by: Anna Bocharova <[email protected]>

* Changelog: upcoming 2.0.1.

* Next version 2.0.1rc1.

* Changelog: also mentioning the code coverage.

* Next version 2.0.1.

* Changelog: also mentioning the fix to documentation.

---------

Co-authored-by: Nadir Zaman Syed <[email protected]>
  • Loading branch information
RobinTail and NDR008 authored Jul 23, 2023
1 parent 1a37790 commit 85de1ba
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

## Version 2

### 2.0.1

- Fixed turning non-inverted relays ON and executing the corresponding optional OS Command when start printing.
- Thanks to [@NDR008](https://github.com/NDR008) contribution, the issue
[#46](https://github.com/borisbu/OctoRelay/issues/46) most is likely resolved.
- Fixed incorrect description of OS Command setting in the documentation.
- Plugin executable code now has `99%` test coverage.
- All following contributions, features and fixes should take this into account.


### 2.0.0

- **Breaking changes**
Expand Down
14 changes: 11 additions & 3 deletions octoprint_octorelay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,11 @@ def print_started(self):
relay_pin = int(settings["relay_pin"])
inverted = settings['inverted_output']
autoONforPrint = settings['autoONforPrint']
cmdON = settings['cmdON']
active = settings["active"]
if autoONforPrint and active:
self._logger.debug("turning on pin: {}, index: {}".format(relay_pin, index))
GPIO.setup(relay_pin, GPIO.OUT)
# XOR with inverted
GPIO.output(relay_pin, inverted != True)
self.turn_on_pin(relay_pin, inverted, cmdON)
self.update_ui()

def print_stopped(self):
Expand Down Expand Up @@ -350,6 +349,15 @@ def turn_off_pin(self, relay_pin, inverted, cmdOFF):
self._logger.info("pin: {} turned off".format(relay_pin))
self.update_ui()

def turn_on_pin(self, relay_pin, inverted, cmdON):
GPIO.setup(relay_pin, GPIO.OUT)
# XOR with inverted
GPIO.output(relay_pin, inverted == False)
GPIO.setwarnings(True)
if cmdON:
os.system(cmdON)
self._logger.info("pin: {} turned on".format(relay_pin))

def update_ui(self):
settings = self.get_settings_defaults()
for index in settings:
Expand Down
35 changes: 26 additions & 9 deletions octoprint_octorelay/test__init.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,20 @@ def test_turn_off_pin(self, systemMock):
systemMock.assert_called_with("CommandMock")
restoreUI()

@patch('os.system')
def test_turn_on_pin(self, systemMock):
# Depending on relay type it should set its pin state and execute the supplied command
cases = [
{ "inverted": True, "expectedOutput": False},
{ "inverted": False, "expectedOutput": True },
]
for case in cases:
self.plugin_instance.turn_on_pin(17, case["inverted"], "CommandMock")
GPIO_mock.setup.assert_called_with(17, "MockedOUT")
GPIO_mock.output.assert_called_with(17, case["expectedOutput"])
GPIO_mock.setwarnings.assert_called_with(True)
systemMock.assert_called_with("CommandMock")

@patch('octoprint.plugin')
def test_on_settings_save(self, octoprintPluginMock):
# Should call the SettingsPlugin event handler with own instance and supplied argument
Expand Down Expand Up @@ -367,30 +381,33 @@ def test_on_after_startup(self):
restoreUI()

def test_print_started(self):
# For relays configured with autoON should set a certain state
# For relays configured with autoON should call turn_on_pin method and update UI
restoreUI = self.mockUpdateUI()
self.plugin_instance.turn_off_timers = { "test": timerMock }
originalTurnOn = self.plugin_instance.turn_on_pin
self.plugin_instance.turn_on_pin = Mock()
self.mockModel()
cases = [
{ "autoOn": True, "inverted": True, "expectedOutput": False},
{ "autoOn": True, "inverted": False, "expectedOutput": True },
{ "autoOn": False, "inverted": True, "expectedOutput": None },
{ "autoOn": False, "inverted": False, "expectedOutput": None }
{ "autoOn": True, "inverted": True, "expectedCall": True},
{ "autoOn": True, "inverted": False, "expectedCall": True },
{ "autoOn": False, "inverted": True, "expectedCall": False },
{ "autoOn": False, "inverted": False, "expectedCall": False }
]
for case in cases:
settingValueMock = {
"active": True,
"relay_pin": 17,
"inverted_output": case["inverted"],
"autoONforPrint": case["autoOn"]
"autoONforPrint": case["autoOn"],
"cmdON": "CommandMock"
}
self.plugin_instance._settings.get = Mock(return_value=settingValueMock)
self.plugin_instance.print_started()
timerMock.cancel.assert_called_with()
if case["expectedOutput"] != None:
GPIO_mock.setup.assert_called_with(17, "MockedOUT")
GPIO_mock.output.assert_called_with(17, case["expectedOutput"])
if case["expectedCall"]:
self.plugin_instance.turn_on_pin.assert_called_with(17, case["inverted"], "CommandMock")
self.plugin_instance.update_ui.assert_called_with()
self.plugin_instance.turn_on_pin = originalTurnOn
restoreUI()

def test_print_stopped(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
plugin_name = "OctoRelay"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "2.0.0"
plugin_version = "2.0.1"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit 85de1ba

Please sign in to comment.