From 48b18048c809ba5e3d962325cb2219b163d70b5b Mon Sep 17 00:00:00 2001 From: ilia Date: Mon, 23 Oct 2023 13:44:07 +0300 Subject: [PATCH] start doing turtle task --- equipment/turtle_device.py | 8 ----- {controls => turtle/controls}/.gitignore | 0 {controls => turtle/controls}/__init__.py | 0 {controls => turtle/controls}/device.py | 21 +++++++----- {equipment => turtle/equipment}/__init__.py | 0 turtle/equipment/turtle_device.py | 34 +++++++++++++++++++ .../tests}/controls/test_device.py | 0 .../tests}/equipment/test_turtle_device.py | 0 8 files changed, 47 insertions(+), 16 deletions(-) delete mode 100644 equipment/turtle_device.py rename {controls => turtle/controls}/.gitignore (100%) rename {controls => turtle/controls}/__init__.py (100%) rename {controls => turtle/controls}/device.py (86%) rename {equipment => turtle/equipment}/__init__.py (100%) create mode 100644 turtle/equipment/turtle_device.py rename {tests => turtle/tests}/controls/test_device.py (100%) rename {tests => turtle/tests}/equipment/test_turtle_device.py (100%) 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/.gitignore b/turtle/controls/.gitignore similarity index 100% rename from controls/.gitignore rename to turtle/controls/.gitignore diff --git a/controls/__init__.py b/turtle/controls/__init__.py similarity index 100% rename from controls/__init__.py rename to turtle/controls/__init__.py diff --git a/controls/device.py b/turtle/controls/device.py similarity index 86% rename from controls/device.py rename to turtle/controls/device.py index d126692..6d1b6ea 100644 --- a/controls/device.py +++ b/turtle/controls/device.py @@ -1,12 +1,16 @@ from dataclasses import dataclass from typing import Optional, Collection, Any -from abc import abstractmethod - -class DeviceLifecycleState: - pass # TODO(Homework #3) +from abc import ABC, abstractmethod, abstractproperty +from enum import Enum -class DevaceError(Exception): +class DeviceLifecycleState(Enum): + INIT = 0 + OPEN = 1 + CLOSE = 2 + + +class DeviceError(Exception): pass @@ -33,8 +37,7 @@ class ActionDescriptor: info: Optional[str] = None -class Device: - # TODO(Homework #3) +class Device(ABC): _state = DeviceLifecycleState.INIT @property @@ -44,9 +47,11 @@ class Device: def close(self): self._state = DeviceLifecycleState.CLOSE + @abstractproperty def trait_descriptors(self) -> Collection[TraitDescriptor]: pass + @abstractproperty def action_descriptors(self) -> Collection[ActionDescriptor]: pass @@ -79,4 +84,4 @@ class SynchronyDevice(Device): @abstractmethod def invalidate(self, trait_name: str): """Invalidate logical state of trait `trait_name`""" - pass \ No newline at end of file + pass diff --git a/equipment/__init__.py b/turtle/equipment/__init__.py similarity index 100% rename from equipment/__init__.py rename to turtle/equipment/__init__.py diff --git a/turtle/equipment/turtle_device.py b/turtle/equipment/turtle_device.py new file mode 100644 index 0000000..e7d1245 --- /dev/null +++ b/turtle/equipment/turtle_device.py @@ -0,0 +1,34 @@ +from turtle import Turtle +from typing import Optional, Collection, Any +from controls.device import SynchronyDevice +from controls.device import TraitDescriptor +from controls.device import ActionDescriptor + + +class TurtleDevice(SynchronyDevice): + def open(self): + self.turtle = Turtle() + super().open() + + def close(self): + self.turtle.clear() + super().close() + + def trait_descriptors(self) -> Collection[TraitDescriptor]: + pass + + def action_descriptors(self) -> Collection[ActionDescriptor]: + pass + + def __getitem__(self, trait_name: str) -> Optional[Any]: + """Return logical state of trait `trait_name`.""" + pass + + def read(self, trait_name: str) -> Any: + raise NonReadableTrait + + def write(self, trait_name: str, value: Any) -> bool: + self.turtle.write() + + def invalidate(self, trait_name: str): + pass \ No newline at end of file diff --git a/tests/controls/test_device.py b/turtle/tests/controls/test_device.py similarity index 100% rename from tests/controls/test_device.py rename to turtle/tests/controls/test_device.py diff --git a/tests/equipment/test_turtle_device.py b/turtle/tests/equipment/test_turtle_device.py similarity index 100% rename from tests/equipment/test_turtle_device.py rename to turtle/tests/equipment/test_turtle_device.py