From 052c0b43e63d223bc0c5dda2543ccc89b0d13ac7 Mon Sep 17 00:00:00 2001 From: ilyavasilev Date: Fri, 27 Oct 2023 00:21:53 +0300 Subject: [PATCH] Made HW3(some part) --- equipment/__init__.py | 0 equipment/turtle_device.py | 8 ---- {controls => scada_system/controls}/device.py | 18 ++++++--- .../equipment}/__init__.py | 0 scada_system/equipment/turtle_device.py | 40 +++++++++++++++++++ .../tests}/controls/test_device.py | 0 .../tests}/equipment/test_turtle_device.py | 0 7 files changed, 52 insertions(+), 14 deletions(-) delete mode 100644 equipment/__init__.py delete mode 100644 equipment/turtle_device.py rename {controls => scada_system/controls}/device.py (86%) rename {controls => scada_system/equipment}/__init__.py (100%) create mode 100644 scada_system/equipment/turtle_device.py rename {tests => scada_system/tests}/controls/test_device.py (100%) rename {tests => scada_system/tests}/equipment/test_turtle_device.py (100%) diff --git a/equipment/__init__.py b/equipment/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/equipment/turtle_device.py b/equipment/turtle_device.py deleted file mode 100644 index 3ba251f..0000000 --- a/equipment/turtle_device.py +++ /dev/null @@ -1,8 +0,0 @@ -from turtle import Turtle -from controls.device import SynchronyDevice - -class TurtleDevice(SynchronyDevice): - pass # TODO(Homework #3) - - - diff --git a/controls/device.py b/scada_system/controls/device.py similarity index 86% rename from controls/device.py rename to scada_system/controls/device.py index d126692..312c8ec 100644 --- a/controls/device.py +++ b/scada_system/controls/device.py @@ -1,9 +1,12 @@ from dataclasses import dataclass from typing import Optional, Collection, Any -from abc import abstractmethod +from abc import ABCMeta, abstractmethod +from enum import Enum -class DeviceLifecycleState: - pass # TODO(Homework #3) +class DeviceLifecycleState(Enum): + INIT = "INIT" + OPEN = "OPEN" + CLOSE = "CLOSE" class DevaceError(Exception): @@ -33,8 +36,7 @@ class ActionDescriptor: info: Optional[str] = None -class Device: - # TODO(Homework #3) +class Device(metaclass=ABCMeta): _state = DeviceLifecycleState.INIT @property @@ -44,9 +46,13 @@ class Device: def close(self): self._state = DeviceLifecycleState.CLOSE + @property + @abstractmethod def trait_descriptors(self) -> Collection[TraitDescriptor]: pass - + + @property + @abstractmethod def action_descriptors(self) -> Collection[ActionDescriptor]: pass diff --git a/controls/__init__.py b/scada_system/equipment/__init__.py similarity index 100% rename from controls/__init__.py rename to scada_system/equipment/__init__.py diff --git a/scada_system/equipment/turtle_device.py b/scada_system/equipment/turtle_device.py new file mode 100644 index 0000000..fc960d0 --- /dev/null +++ b/scada_system/equipment/turtle_device.py @@ -0,0 +1,40 @@ +import turtle +from typing import Optional, Collection, Any +from controls.device import SynchronyDevice +import time +import inspect + +class TurtleDevice(SynchronyDevice): + def open(self): + super().open() + turtle.Turtle() + + def close(self): + super().close() + turtle.bye() + + def execute(self, action_name: str, *args, **kwargs): + getattr(turtle, action_name)(args[0], *kwargs) + + def read(self, trait_name: str): + pass + + def write(self, trait_name: str, value: Any) -> bool: + pass + + def invalidate(self, trait_name: str): + pass + + def trait_descriptors(self): + traits = [attr for attr in turtle.Turtle.__dict__ + if attr.startswith('__') and not attr.startswith('_')] + return traits + + def action_descriptors(self): + actions = [(name, func.__doc__) for name, func in inspect.getmembers(turtle.Turtle) + if callable(func) and not name.startswith('__') and not name.startswith('_')] + return actions + + def __getitem__(self, trait_name: str): + """Return logical state of trait `trait_name`.""" + pass diff --git a/tests/controls/test_device.py b/scada_system/tests/controls/test_device.py similarity index 100% rename from tests/controls/test_device.py rename to scada_system/tests/controls/test_device.py diff --git a/tests/equipment/test_turtle_device.py b/scada_system/tests/equipment/test_turtle_device.py similarity index 100% rename from tests/equipment/test_turtle_device.py rename to scada_system/tests/equipment/test_turtle_device.py