start doing turtle task

This commit is contained in:
ilia 2023-10-23 13:44:07 +03:00
parent 5c5d61ec03
commit 48b18048c8
8 changed files with 47 additions and 16 deletions

View File

@ -1,8 +0,0 @@
from turtle import Turtle
from controls.device import SynchronyDevice
class TurtleDevice(SynchronyDevice):
pass # TODO(Homework #3)

View File

@ -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
pass

View File

@ -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