Compare commits
5 commits
Author | SHA1 | Date | |
---|---|---|---|
c9a0f7dcb3 | |||
9eef6418a9 | |||
1f24d7486b | |||
ce1b61b952 | |||
4ea79271e7 |
9 changed files with 83 additions and 17 deletions
|
@ -1,5 +1,5 @@
|
||||||
[bumpversion]
|
[bumpversion]
|
||||||
current_version = 0.1.4
|
current_version = 0.1.5
|
||||||
commit = True
|
commit = True
|
||||||
tag = True
|
tag = True
|
||||||
|
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -6,7 +6,7 @@ with open('README.rst') as f:
|
||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name='TSGRain Controller',
|
name='TSGRain Controller',
|
||||||
version='0.1.4',
|
version='0.1.5',
|
||||||
author='ThetaDev',
|
author='ThetaDev',
|
||||||
description='TSGRain irrigation controller',
|
description='TSGRain irrigation controller',
|
||||||
long_description=README,
|
long_description=README,
|
||||||
|
|
|
@ -45,7 +45,7 @@ def app(mocker):
|
||||||
assert not app.is_running()
|
assert not app.is_running()
|
||||||
|
|
||||||
|
|
||||||
def test_start_task(app):
|
def test_request_task(app):
|
||||||
# Manually start a task (like via button press)
|
# Manually start a task (like via button press)
|
||||||
res = app.request_task(
|
res = app.request_task(
|
||||||
models.TaskRequest(source=models.Source.MANUAL,
|
models.TaskRequest(source=models.Source.MANUAL,
|
||||||
|
@ -80,13 +80,13 @@ def test_start_task(app):
|
||||||
assert res.stopped
|
assert res.stopped
|
||||||
|
|
||||||
|
|
||||||
def test_start_task_queue(app):
|
def test_request_task_queue(app):
|
||||||
# Manually start a task (like via button press)
|
# Enqueue and start a new task
|
||||||
res = app.request_task(
|
res = app.request_task(
|
||||||
models.TaskRequest(source=models.Source.MANUAL,
|
models.TaskRequest(source=models.Source.MANUAL,
|
||||||
zone_id=2,
|
zone_id=2,
|
||||||
duration=30,
|
duration=30,
|
||||||
queuing=False,
|
queuing=True,
|
||||||
cancelling=True))
|
cancelling=True))
|
||||||
assert res.started
|
assert res.started
|
||||||
assert not res.stopped
|
assert not res.stopped
|
||||||
|
@ -135,6 +135,51 @@ def test_start_task_queue(app):
|
||||||
assert res.stopped
|
assert res.stopped
|
||||||
|
|
||||||
|
|
||||||
|
def test_start_task(app):
|
||||||
|
# Manually start a task (like via button press)
|
||||||
|
assert app.start_task(models.Source.MANUAL, 2, 30, False)
|
||||||
|
|
||||||
|
# Queue processing time
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
# Try to start the same task again -> nothing happens
|
||||||
|
assert not app.start_task(models.Source.MANUAL, 2, 30, False)
|
||||||
|
|
||||||
|
|
||||||
|
def test_start_task_queue(app):
|
||||||
|
# Enqueue and start a new task
|
||||||
|
assert app.start_task(models.Source.MANUAL, 2, 30, True)
|
||||||
|
|
||||||
|
# Queue processing time
|
||||||
|
time.sleep(0.1)
|
||||||
|
assert app.queue.running_task.zone_id == 2
|
||||||
|
|
||||||
|
# Duplicate task should not be enqueued
|
||||||
|
assert not app.start_task(models.Source.MANUAL, 2, 30, True)
|
||||||
|
|
||||||
|
# Enqueue new tasks
|
||||||
|
assert app.start_task(models.Source.MANUAL, 3, 30, True)
|
||||||
|
assert app.start_task(models.Source.SCHEDULE, 2, 30, True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_stop_task(app):
|
||||||
|
# Enqueue and start a new task
|
||||||
|
assert app.start_task(models.Source.MANUAL, 2, 30, True)
|
||||||
|
|
||||||
|
# Queue processing time
|
||||||
|
time.sleep(0.1)
|
||||||
|
assert app.queue.running_task.zone_id == 2
|
||||||
|
|
||||||
|
# Stop task
|
||||||
|
assert not app.stop_task(models.Source.MANUAL, 3)
|
||||||
|
assert app.stop_task(models.Source.MANUAL, 2)
|
||||||
|
|
||||||
|
# Queue processing time
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
assert app.queue.running_task is None
|
||||||
|
|
||||||
|
|
||||||
def test_crud_job(app):
|
def test_crud_job(app):
|
||||||
# Insert jobs
|
# Insert jobs
|
||||||
job1 = models.Job.deserialize(JOB1_DATA)
|
job1 = models.Job.deserialize(JOB1_DATA)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
__version__ = '0.1.4'
|
__version__ = '0.1.5'
|
||||||
|
|
|
@ -121,7 +121,7 @@ class Application(models.AppInterface):
|
||||||
|
|
||||||
task = models.Task(source, zone_id, duration)
|
task = models.Task(source, zone_id, duration)
|
||||||
task.validate(self)
|
task.validate(self)
|
||||||
return self.queue.enqueue(task, not queuing)
|
return self.queue.enqueue(task, queuing)
|
||||||
|
|
||||||
def stop_task(self, source: models.Source, zone_id: int) -> bool:
|
def stop_task(self, source: models.Source, zone_id: int) -> bool:
|
||||||
for task in self.queue.tasks:
|
for task in self.queue.tasks:
|
||||||
|
@ -176,6 +176,7 @@ class Application(models.AppInterface):
|
||||||
systimecfg.set_system_timezone(tz, self.cfg.cmd_set_timezone)
|
systimecfg.set_system_timezone(tz, self.cfg.cmd_set_timezone)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
|
"""Starte die Anwendung"""
|
||||||
logging.info('Starting application')
|
logging.info('Starting application')
|
||||||
self._running = True
|
self._running = True
|
||||||
self.io.start()
|
self.io.start()
|
||||||
|
@ -185,6 +186,7 @@ class Application(models.AppInterface):
|
||||||
self.grpc_server.start()
|
self.grpc_server.start()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
"""Stoppe die Anwendung"""
|
||||||
logging.info('Stopping application')
|
logging.info('Stopping application')
|
||||||
self._running = False
|
self._running = False
|
||||||
self.grpc_server.stop(None)
|
self.grpc_server.stop(None)
|
||||||
|
|
|
@ -238,7 +238,7 @@ class _MCP23017Device:
|
||||||
Beispiel: ``0x27/B0`` (MCP23017 mit I2C-Adresse 0x27, Pin B0)
|
Beispiel: ``0x27/B0`` (MCP23017 mit I2C-Adresse 0x27, Pin B0)
|
||||||
|
|
||||||
Um den Zustand eines Geräts zu invertieren, einfach ``/!``
|
Um den Zustand eines Geräts zu invertieren, einfach ``/!``
|
||||||
an den Konfiguraionsstring anfügen: ``0x27/B0/!``
|
an den Konfigurationsstring anfügen: ``0x27/B0/!``
|
||||||
|
|
||||||
:param cfg_str: Konfigurationsstring
|
:param cfg_str: Konfigurationsstring
|
||||||
:return: Neues ``_MCP23017Device``-Objekt
|
:return: Neues ``_MCP23017Device``-Objekt
|
||||||
|
|
|
@ -96,6 +96,10 @@ class Job:
|
||||||
)
|
)
|
||||||
|
|
||||||
def validate(self, app: 'AppInterface'):
|
def validate(self, app: 'AppInterface'):
|
||||||
|
"""
|
||||||
|
Prüfe, ob der Task gültige Daten enthält
|
||||||
|
(Zonen existieren, Bewässerungszeit > 0)
|
||||||
|
"""
|
||||||
if not self.zones:
|
if not self.zones:
|
||||||
raise util.InvalidInputException('No zones set')
|
raise util.InvalidInputException('No zones set')
|
||||||
if self.duration < 1:
|
if self.duration < 1:
|
||||||
|
|
|
@ -129,9 +129,20 @@ class StoppableThread(threading.Thread):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run_cycle(self):
|
def run_cycle(self):
|
||||||
pass
|
"""
|
||||||
|
Führe einen Durchlauf des Threads aus.
|
||||||
|
|
||||||
|
Diese Funktion darf nicht blockieren, sonst kann der
|
||||||
|
Thread nicht gestoppt werden.
|
||||||
|
"""
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
"""
|
||||||
|
Führe die ``run_cycle()``-Funktion in
|
||||||
|
Endlosschleife aus, mit einer durch das
|
||||||
|
``interval``-Attribut bestimmten Verzögerung zwischen
|
||||||
|
den Durchläufen.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
self.setup()
|
self.setup()
|
||||||
|
|
||||||
|
@ -146,6 +157,10 @@ class StoppableThread(threading.Thread):
|
||||||
sys.excepthook(*sys.exc_info())
|
sys.excepthook(*sys.exc_info())
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
"""
|
||||||
|
Stoppe den Thread und warte bis er beendet. Dies dauert
|
||||||
|
maximal ``interval`` + Durchlaufzeit von ``run_cycle()``.
|
||||||
|
"""
|
||||||
self._stop_signal.set()
|
self._stop_signal.set()
|
||||||
try:
|
try:
|
||||||
self.join()
|
self.join()
|
||||||
|
|
Loading…
Add table
Reference in a new issue