Made HW3(some part)
This commit is contained in:
parent
2ab3e65ebc
commit
052c0b43e6
@ -1,8 +0,0 @@
|
|||||||
from turtle import Turtle
|
|
||||||
from controls.device import SynchronyDevice
|
|
||||||
|
|
||||||
class TurtleDevice(SynchronyDevice):
|
|
||||||
pass # TODO(Homework #3)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Optional, Collection, Any
|
from typing import Optional, Collection, Any
|
||||||
from abc import abstractmethod
|
from abc import ABCMeta, abstractmethod
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
class DeviceLifecycleState:
|
class DeviceLifecycleState(Enum):
|
||||||
pass # TODO(Homework #3)
|
INIT = "INIT"
|
||||||
|
OPEN = "OPEN"
|
||||||
|
CLOSE = "CLOSE"
|
||||||
|
|
||||||
|
|
||||||
class DevaceError(Exception):
|
class DevaceError(Exception):
|
||||||
@ -33,8 +36,7 @@ class ActionDescriptor:
|
|||||||
info: Optional[str] = None
|
info: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
class Device:
|
class Device(metaclass=ABCMeta):
|
||||||
# TODO(Homework #3)
|
|
||||||
_state = DeviceLifecycleState.INIT
|
_state = DeviceLifecycleState.INIT
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -44,9 +46,13 @@ class Device:
|
|||||||
def close(self):
|
def close(self):
|
||||||
self._state = DeviceLifecycleState.CLOSE
|
self._state = DeviceLifecycleState.CLOSE
|
||||||
|
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
def trait_descriptors(self) -> Collection[TraitDescriptor]:
|
def trait_descriptors(self) -> Collection[TraitDescriptor]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
def action_descriptors(self) -> Collection[ActionDescriptor]:
|
def action_descriptors(self) -> Collection[ActionDescriptor]:
|
||||||
pass
|
pass
|
||||||
|
|
40
scada_system/equipment/turtle_device.py
Normal file
40
scada_system/equipment/turtle_device.py
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user