def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the Ziggo Mediabox XL platform.""" from ziggo_mediabox_xl import ZiggoMediaboxXL hass.data[DATA_KNOWN_DEVICES] = known_devices = set() # Is this a manual configuration? if config.get(CONF_HOST) is not None: host = config.get(CONF_HOST) name = config.get(CONF_NAME) elif discovery_info is not None: host = discovery_info.get('host') name = discovery_info.get('name') else: _LOGGER.error("Cannot determine device") return # Only add a device once, so discovered devices do not override manual # config. hosts = [] ip_addr = socket.gethostbyname(host) if ip_addr not in known_devices: try: mediabox = ZiggoMediaboxXL(ip_addr) if mediabox.test_connection(): hosts.append(ZiggoMediaboxXLDevice(mediabox, host, name)) known_devices.add(ip_addr) else: _LOGGER.error("Can't connect to %s", host) except socket.error as error: _LOGGER.error("Can't connect to %s: %s", host, error) else: _LOGGER.info("Ignoring duplicate Ziggo Mediabox XL %s", host) add_devices(hosts, True)
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Ziggo Mediabox XL platform.""" from ziggo_mediabox_xl import ZiggoMediaboxXL hass.data[DATA_KNOWN_DEVICES] = known_devices = set() # Is this a manual configuration? if config.get(CONF_HOST) is not None: host = config.get(CONF_HOST) name = config.get(CONF_NAME) elif discovery_info is not None: host = discovery_info.get('host') name = discovery_info.get('name') else: _LOGGER.error("Cannot determine device") return # Only add a device once, so discovered devices do not override manual # config. hosts = [] ip_addr = socket.gethostbyname(host) if ip_addr not in known_devices: try: mediabox = ZiggoMediaboxXL(ip_addr) if mediabox.test_connection(): hosts.append(ZiggoMediaboxXLDevice(mediabox, host, name)) known_devices.add(ip_addr) else: _LOGGER.error("Can't connect to %s", host) except socket.error as error: _LOGGER.error("Can't connect to %s: %s", host, error) else: _LOGGER.info("Ignoring duplicate Ziggo Mediabox XL %s", host) add_entities(hosts, True)
def onStart(self): Domoticz.Debug("onStart called") if Parameters["Mode6"] == "Debug": Domoticz.Debugging(1) else: Domoticz.Debugging(0) # Images # Check if images are in database if "xfr_ziggomediaboxxl" not in Images: Domoticz.Image("xfr_ziggomediaboxxl.zip").Create() try: image = Images["xfr_ziggomediaboxxl"].ID except: image = 0 Domoticz.Debug("Image created. ID: " + str(image)) # Validate parameters # Create devices if (len(Devices) == 0): Domoticz.Device(Unit=self.__UNIT_STATUS, Name="Status", Type=17, Switchtype=17, Image=image, Used=1).Create() # Log config DumpConfigToLog() # Connection self._box = ZiggoMediaboxXL(Parameters["Address"])
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Ziggo Mediabox XL platform.""" from ziggo_mediabox_xl import ZiggoMediaboxXL hass.data[DATA_KNOWN_DEVICES] = known_devices = set() # Is this a manual configuration? if config.get(CONF_HOST) is not None: host = config.get(CONF_HOST) name = config.get(CONF_NAME) manual_config = True elif discovery_info is not None: host = discovery_info.get('host') name = discovery_info.get('name') manual_config = False else: _LOGGER.error("Cannot determine device") return # Only add a device once, so discovered devices do not override manual # config. hosts = [] connection_successful = False ip_addr = socket.gethostbyname(host) if ip_addr not in known_devices: try: # Mediabox instance with a timeout of 3 seconds. mediabox = ZiggoMediaboxXL(ip_addr, 3) # Check if a connection can be established to the device. if mediabox.test_connection(): connection_successful = True else: if manual_config: _LOGGER.info("Can't connect to %s", host) else: _LOGGER.error("Can't connect to %s", host) # When the device is in eco mode it's not connected to the network # so it needs to be added anyway if it's configured manually. if manual_config or connection_successful: hosts.append( ZiggoMediaboxXLDevice(mediabox, host, name, connection_successful)) known_devices.add(ip_addr) except socket.error as error: _LOGGER.error("Can't connect to %s: %s", host, error) else: _LOGGER.info("Ignoring duplicate Ziggo Mediabox XL %s", host) add_entities(hosts, True)
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Ziggo Mediabox XL platform.""" from ziggo_mediabox_xl import ZiggoMediaboxXL hass.data[DATA_KNOWN_DEVICES] = known_devices = set() # Is this a manual configuration? if config.get(CONF_HOST) is not None: host = config.get(CONF_HOST) name = config.get(CONF_NAME) manual_config = True elif discovery_info is not None: host = discovery_info.get('host') name = discovery_info.get('name') manual_config = False else: _LOGGER.error("Cannot determine device") return # Only add a device once, so discovered devices do not override manual # config. hosts = [] connection_successful = False ip_addr = socket.gethostbyname(host) if ip_addr not in known_devices: try: # Mediabox instance with a timeout of 3 seconds. mediabox = ZiggoMediaboxXL(ip_addr, 3) # Check if a connection can be established to the device. if mediabox.test_connection(): connection_successful = True else: if manual_config: _LOGGER.info("Can't connect to %s", host) else: _LOGGER.error("Can't connect to %s", host) # When the device is in eco mode it's not connected to the network # so it needs to be added anyway if it's configured manually. if manual_config or connection_successful: hosts.append(ZiggoMediaboxXLDevice(mediabox, host, name, connection_successful)) known_devices.add(ip_addr) except socket.error as error: _LOGGER.error("Can't connect to %s: %s", host, error) else: _LOGGER.info("Ignoring duplicate Ziggo Mediabox XL %s", host) add_entities(hosts, True)
host = discovery_info["host"] name = discovery_info.get("name") manual_config = False else: _LOGGER.error("Cannot determine device") return # Only add a device once, so discovered devices do not override manual # config. hosts = [] connection_successful = False ip_addr = socket.gethostbyname(host) if ip_addr not in known_devices: try: # Mediabox instance with a timeout of 3 seconds. mediabox = ZiggoMediaboxXL(ip_addr, 3) # Check if a connection can be established to the device. if mediabox.test_connection(): connection_successful = True else: if manual_config: _LOGGER.info("Can't connect to %s", host) else: _LOGGER.error("Can't connect to %s", host) # When the device is in eco mode it's not connected to the network # so it needs to be added anyway if it's configured manually. if manual_config or connection_successful: hosts.append( ZiggoMediaboxXLDevice(mediabox, host, name, connection_successful)) known_devices.add(ip_addr)
class BasePlugin: __HEARTBEATS2MIN = 6 __MINUTES = 1 # or use a parameter __MSTAT_OFF = 0 __MSTAT_ON = 1 __MSTAT_PAUSED = 2 __MSTAT_STOPPED = 3 __MSTAT_VIDEO = 4 __MSTAT_AUDIO = 5 __MSTAT_PHOTO = 6 __MSTAT_PLAYING = 7 __MSTAT_DISCONNECTED = 8 __MSTAT_SLEEPING = 9 __MSTAT_UNKNOWN = 10 # Device units __UNIT_STATUS = 1 def __init__(self): self._runAgain = 0 self._box = None def onStart(self): Domoticz.Debug("onStart called") if Parameters["Mode6"] == "Debug": Domoticz.Debugging(1) else: Domoticz.Debugging(0) # Images # Check if images are in database if "xfr_ziggomediaboxxl" not in Images: Domoticz.Image("xfr_ziggomediaboxxl.zip").Create() try: image = Images["xfr_ziggomediaboxxl"].ID except: image = 0 Domoticz.Debug("Image created. ID: " + str(image)) # Validate parameters # Create devices if (len(Devices) == 0): Domoticz.Device(Unit=self.__UNIT_STATUS, Name="Status", Type=17, Switchtype=17, Image=image, Used=1).Create() # Log config DumpConfigToLog() # Connection self._box = ZiggoMediaboxXL(Parameters["Address"]) def onStop(self): Domoticz.Debug("onStop called") def onConnect(self, Connection, Status, Description): Domoticz.Debug("onConnect called") def onMessage(self, Connection, Data): Domoticz.Debug("onMessage: " + Connection.Name) def onCommand(self, Unit, Command, Level, Hue): Domoticz.Debug("onCommand for Unit " + str(Unit) + ": Command '" + str(Command) + "', Level: " + str(Level)) Command = Command.strip() action, sep, params = Command.partition(' ') action = action.upper() # if not self._box.turned_on(): self._box.send_keys(["POWER"]) # if action == "ON": self._box.send_keys(["POWER"]) elif action == "OFF": self._box.send_keys(["POWER"]) elif action == "UP": self._box.send_keys(["DPAD_UP"]) elif action == "DOWN": self._box.send_keys(["DPAD_DOWN"]) elif action == "LEFT": self._box.send_keys(["DPAD_LEFT"]) elif action == "RIGHT": self._box.send_keys(["DPAD_RIGHT"]) elif action == "INFO": self._box.send_keys(["INFO"]) elif action == "SELECT": self._box.send_keys(["OK"]) elif action == "BACK": self._box.send_keys(["BACK"]) elif action == "CONTEXTMENU": self._box.send_keys(["MENU"]) elif action == "CHANNELUP": self._box.send_keys(["CHAN_UP"]) elif action == "CHANNELDOWN": self._box.send_keys(["CHAN_DOWN"]) elif action == "STOP": self._box.send_keys(["STOP"]) elif action == "FASTFORWARD" or action == "BIGSTEPFORWARD": self._box.send_keys(["FWD"]) elif action == "REWIND" or action == "BIGSTEPBACK": self._box.send_keys(["CHAN_UP"]) elif action == "PLAYPAUSE": self._box.send_keys(["PAUSE"]) def onNotification(self, Name, Subject, Text, Status, Priority, Sound, ImageFile): Domoticz.Debug("onNotification: " + Name + "," + Subject + "," + Text + "," + Status + "," + str(Priority) + "," + Sound + "," + ImageFile) def onDisconnect(self, Connection): Domoticz.Debug("onDisconnect: " + Connection.Name) def onHeartbeat(self): Domoticz.Debug("onHeartbeat") if self._box.turned_on(): UpdateDevice(self.__UNIT_STATUS, self.__MSTAT_ON, "") else: UpdateDevice(self.__UNIT_STATUS, self.__MSTAT_OFF, "")