Skip to content

Commit 4e6cd0e

Browse files
Actuator event ORM fix (#190)
* Fixed actuator command conversion in ORM * Version updated
1 parent 115506a commit 4e6cd0e

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

wadas/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
# Date: 2024-08-14
1818
# Description: module to keep track of WADAS version
1919

20-
__version__ = "v0.9.14"
20+
__version__ = "v0.9.15"
2121
__dbversion__ = __version__

wadas/domain/database.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,31 @@ def domain_to_orm(domain_object, foreign_key=None):
884884
creation_date=get_precise_timestamp(),
885885
)
886886
elif isinstance(domain_object, ActuationEvent):
887-
cmd = DeterrentActuator.Commands(domain_object.command)
887+
actuator = Actuator.actuators.get(domain_object.actuator_id)
888+
889+
if actuator is None:
890+
logger.error(
891+
"Unable to find actuator ID '%s' in the pool of available actuators. Aborting.",
892+
domain_object.actuator_id,
893+
)
894+
return None
895+
896+
try:
897+
Commands = actuator.__class__.Commands
898+
cmd = Commands(domain_object.command)
899+
except AttributeError:
900+
logger.error(
901+
"Actuator class %s does not define a Commands enum. Aborting.",
902+
actuator.__class__.__name__,
903+
)
904+
return None
905+
except ValueError:
906+
logger.error(
907+
"Invalid command '%s' for actuator class %s. Aborting.",
908+
domain_object.command,
909+
actuator.__class__.__name__,
910+
)
911+
return None
888912

889913
return ORMActuationEvent(
890914
actuator_id=foreign_key[0],

0 commit comments

Comments
 (0)