def __init__(self, name, host): """Initialize the Remote.""" from jvc_projector import JVCProjector self._name = name or DEVICE_DEFAULT_NAME self._host = host self._last_command_sent = None self._jvc = JVCProjector(host) self._state = None
from jvc_projector import JVCProjector import sys if len(sys.argv) != 2: print('Usage: python ./get_power_state.py <projector_ip>') else: projectorIp = sys.argv[1] projector = JVCProjector(projectorIp) if projector.is_on(): print('ON') else: print('OFF')
from jvc_projector import JVCProjector import sys if len(sys.argv) != 3: print('Usage: python ./set_power_state.py <projector_ip> [ON|OFF]') else: projectorIp = sys.argv[1] powerState = sys.argv[2] projector = JVCProjector(projectorIp) if powerState == "ON": projector.power_on() else: projector.power_off()
class JVCRemote(remote.RemoteEntity): """Home assistant JVC remote representation""" def __init__(self, name, host): """Initialize the Remote.""" from jvc_projector import JVCProjector self._name = name or DEVICE_DEFAULT_NAME self._host = host self._last_command_sent = None self._jvc = JVCProjector(host) self._state = None self._power_state = 'N/A' @property def should_poll(self): # poll the device so we know if it was state changed # via an external method, like the physical remote return True @property def name(self): """Return the name of the device if any.""" return self._name async def async_update(self): await self.async_update_state() @property def is_on(self): """Return true if remote is on.""" return self._state @property def device_state_attributes(self): """Return device state attributes.""" if self._power_state in ['lamp_on', 'reserved']: self._state = True else: self._state = False return { 'last_command_sent': self._last_command_sent if self._last_command_sent is not None else 'N/A', 'power_state': self._power_state, } async def async_turn_on(self, **kwargs): """Turn the remote on.""" await self.async_send_command('power_on') self._state = True async def async_turn_off(self, **kwargs): """Turn the remote off.""" await self.async_send_command('power_off') self._state = False async def async_send_command(self, command, **kwargs): """Send a command to a device.""" if type(command) != list: command = [command] for com in command: _LOGGER.info(f"sending command: {com}") try: command_sent = self._jvc.command(com) except Exception: # when an error occured during sending, command execution probably failed command_sent = False if not command_sent: self._last_command_sent = "N/A" continue else: self._last_command_sent = com async def async_update_state(self): """"Update the state with the Power Status (if available)""" try: self._power_state = self._jvc.power_state() except Exception: self._power_state = 'unknown'
class JVCRemote(remote.RemoteDevice): """Home assistant JVC remote representation""" def __init__(self, name, host): """Initialize the Remote.""" from jvc_projector import JVCProjector self._name = name or DEVICE_DEFAULT_NAME self._host = host self._last_command_sent = None self._jvc = JVCProjector(host) self._state = None @property def should_poll(self): # poll the device so we know if it was state changed # via an external method, like the physical remote return True @property def name(self): """Return the name of the device if any.""" return self._name def update(self): self._state = self._jvc.is_on() @property def is_on(self): """Return true if remote is on.""" return self._state @property def device_state_attributes(self): """Return device state attributes.""" if self._last_command_sent is not None: return {'last_command_sent': self._last_command_sent} async def async_turn_on(self, **kwargs): """Turn the remote on.""" _LOGGER.info("powering on") self._jvc.power_on() self._state = True await asyncio.sleep(1) self.schedule_update_ha_state(True) async def async_turn_off(self, **kwargs): """Turn the remote off.""" _LOGGER.info("powering off") self._jvc.power_off() self._state = False await asyncio.sleep(1) self.schedule_update_ha_state(True) async def async_send_command(self, command, **kwargs): """Send a command to a device.""" for com in command: _LOGGER.info(f"sending command: {com}") command_sent = self._jvc.command(com) if not command_sent: self._last_command_sent = "N/A" continue else: self._last_command_sent = com await asyncio.sleep(1) self.schedule_update_ha_state()