1 """Use serial protocol of Acer projector to obtain state of the projector."""
3 from __future__
import annotations
10 import voluptuous
as vol
13 PLATFORM_SCHEMA
as SWITCH_PLATFORM_SCHEMA,
34 DEFAULT_WRITE_TIMEOUT,
42 _LOGGER = logging.getLogger(__name__)
44 PLATFORM_SCHEMA = SWITCH_PLATFORM_SCHEMA.extend(
46 vol.Required(CONF_FILENAME): cv.isdevice,
47 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
48 vol.Optional(CONF_TIMEOUT, default=DEFAULT_TIMEOUT): cv.positive_int,
50 CONF_WRITE_TIMEOUT, default=DEFAULT_WRITE_TIMEOUT
59 add_entities: AddEntitiesCallback,
60 discovery_info: DiscoveryInfoType |
None =
None,
62 """Connect with serial port and return Acer Projector."""
63 serial_port = config[CONF_FILENAME]
64 name = config[CONF_NAME]
65 timeout = config[CONF_TIMEOUT]
66 write_timeout = config[CONF_WRITE_TIMEOUT]
72 """Represents an Acer Projector as a switch."""
83 """Init of the Acer projector."""
85 port=serial_port, timeout=timeout, write_timeout=write_timeout
90 LAMP_HOURS: STATE_UNKNOWN,
91 INPUT_SOURCE: STATE_UNKNOWN,
92 ECO_MODE: STATE_UNKNOWN,
96 """Write to the projector and read the return."""
102 if not self.
serialserial.is_open:
104 self.
serialserial.write(msg.encode(
"utf-8"))
108 ret = self.
serialserial.read_until(size=20).decode(
"utf-8")
109 except serial.SerialException:
110 _LOGGER.error(
"Problem communicating with %s", self.
_serial_port_serial_port)
115 """Write msg, obtain answer and format output."""
118 if match := re.search(
r"\r(.+)\r", awns):
119 return match.group(1)
123 """Get the latest state from the projector."""
128 elif awns ==
"Lamp 0":
135 if msg := CMD_DICT.get(key):
141 """Turn the projector on."""
142 msg = CMD_DICT[STATE_ON]
147 """Turn the projector off."""
148 msg = CMD_DICT[STATE_OFF]
None __init__(self, str serial_port, str name, int timeout, int write_timeout)
str _write_read_format(self, str msg)
_attr_extra_state_attributes
None turn_on(self, **Any kwargs)
None turn_off(self, **Any kwargs)
str _write_read(self, str msg)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None open(self, **Any kwargs)