pyh0n/pyhon/appliances/base.py

26 lines
881 B
Python
Raw Normal View History

2023-06-28 22:32:11 +05:30
from typing import Dict, Any, TYPE_CHECKING
from pyhon.parameter.program import HonParameterProgram
if TYPE_CHECKING:
from pyhon.appliance import HonAppliance
2023-05-29 22:28:50 +05:30
class ApplianceBase:
2023-06-28 22:32:11 +05:30
def __init__(self, appliance: "HonAppliance"):
2023-05-29 22:28:50 +05:30
self.parent = appliance
2023-06-28 22:32:11 +05:30
def attributes(self, data: Dict[str, Any]) -> Dict[str, Any]:
2023-05-29 22:28:50 +05:30
program_name = "No Program"
2023-06-13 03:42:29 +05:30
if program := int(str(data.get("parameters", {}).get("prCode", "0"))):
2023-06-08 23:20:56 +05:30
if start_cmd := self.parent.settings.get("startProgram.program"):
2023-06-28 22:32:11 +05:30
if isinstance(start_cmd, HonParameterProgram) and (
ids := start_cmd.ids
):
2023-06-08 23:20:56 +05:30
program_name = ids.get(program, program_name)
2023-05-29 22:28:50 +05:30
data["programName"] = program_name
2023-06-08 23:20:56 +05:30
return data
2023-05-29 22:28:50 +05:30
2023-06-28 22:32:11 +05:30
def settings(self, settings: Dict[str, Any]) -> Dict[str, Any]:
2023-05-29 22:28:50 +05:30
return settings