Add all methods realized
This commit is contained in:
parent
4363ac2dfd
commit
e9a0b2832e
@ -15,21 +15,31 @@ class TurtleDevice(SynchronyDevice):
|
||||
super().__init__()
|
||||
self.open()
|
||||
|
||||
def open(self):
|
||||
def open(self) -> None:
|
||||
self.turtle = Turtle()
|
||||
|
||||
def close(self):
|
||||
def close(self)-> None:
|
||||
del self.turtle
|
||||
self.close()
|
||||
|
||||
def execute(self, action_name: str, *args, **kwargs):
|
||||
pass
|
||||
def execute(self, action_name: str, *args, **kwargs) -> None:
|
||||
actions = self.action_descriptors
|
||||
for action in actions:
|
||||
if action.name == action_name:
|
||||
# NOTE: судя по заданию, должен быть такой чекер, но почему-то у меня inspect плохо спарсил типы
|
||||
# везде empty_time, хотя судя по доке в модуле typos проставлены
|
||||
# for argument in kwargs:
|
||||
# action_tmp_argument_type = action.arguments[argument]
|
||||
# given_method_tmp_argument = type(kwargs[argument])
|
||||
# assert (
|
||||
# action_tmp_argument_type == given_method_tmp_argument
|
||||
# ), f"Переданный аргумент должен быть типа {action_tmp_argument_type}, вы передали {given_method_tmp_argument}"
|
||||
getattr(self.turtle, action_name)(*args, **kwargs)
|
||||
return
|
||||
raise NoSuchAction
|
||||
|
||||
def read(self, trait_name: str) -> Any:
|
||||
traits = self.trait_descriptors
|
||||
for trait in traits:
|
||||
if trait.name == trait_name:
|
||||
return self.turtle.__getattribute__(trait_name)
|
||||
raise NoSuchTrait
|
||||
return Turtle().__getattribute__(trait_name)
|
||||
|
||||
def write(self, trait_name: str, value: Any) -> bool:
|
||||
traits = self.trait_descriptors
|
||||
@ -43,11 +53,17 @@ class TurtleDevice(SynchronyDevice):
|
||||
return True
|
||||
raise NoSuchTrait
|
||||
|
||||
def invalidate(self, trait_name: str):
|
||||
pass
|
||||
def invalidate(self, trait_name: str) -> None:
|
||||
# NOTE: если я правильно понял, что должен делать метод
|
||||
self.write(trait_name=trait_name, value=Turtle().__getattribute__(trait_name))
|
||||
return
|
||||
|
||||
def __getitem__(self, trait_name: str) -> Optional[Any]:
|
||||
pass
|
||||
traits = self.trait_descriptors
|
||||
for trait in traits:
|
||||
if trait.name == trait_name:
|
||||
return self.turtle.__getattribute__(trait_name)
|
||||
raise NoSuchTrait
|
||||
|
||||
@property
|
||||
def trait_descriptors(self) -> Collection[TraitDescriptor]:
|
||||
|
Loading…
Reference in New Issue
Block a user