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