def setup_platform( hass: HomeAssistant, config: ConfigType, add_entities: AddEntitiesCallback, discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up the Greenwave Reality Platform.""" host = config.get(CONF_HOST) tokenfilename = hass.config.path(".greenwave") if config.get(CONF_VERSION) == 3: if os.path.exists(tokenfilename): with open(tokenfilename, encoding="utf8") as tokenfile: token = tokenfile.read() else: try: token = greenwave.grab_token(host, "hass", "homeassistant") except PermissionError: _LOGGER.error("The Gateway Is Not In Sync Mode") raise with open(tokenfilename, "w+", encoding="utf8") as tokenfile: tokenfile.write(token) else: token = None bulbs = greenwave.grab_bulbs(host, token) add_entities( GreenwaveLight(device, host, token, GatewayData(host, token)) for device in bulbs.values())
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Greenwave Reality Platform.""" import greenwavereality as greenwave import os host = config.get(CONF_HOST) tokenfile = hass.config.path(".greenwave") if config.get(CONF_VERSION) == 3: if os.path.exists(tokenfile): with open(tokenfile) as tokenfile: token = tokenfile.read() else: try: token = greenwave.grab_token(host, "hass", "homeassistant") except PermissionError: _LOGGER.error("The Gateway Is Not In Sync Mode") raise with open(tokenfile, "w+") as tokenfile: tokenfile.write(token) else: token = None bulbs = greenwave.grab_bulbs(host, token) add_entities( GreenwaveLight(device, host, token, GatewayData(host, token)) for device in bulbs.values())
def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the Greenwave Reality Platform.""" import greenwavereality as greenwave import os host = config.get(CONF_HOST) tokenfile = hass.config.path('.greenwave') if config.get(CONF_VERSION) == 3: if os.path.exists(tokenfile): tokenfile = open(tokenfile) token = tokenfile.read() tokenfile.close() else: try: token = greenwave.grab_token(host, 'hass', 'homeassistant') except PermissionError: _LOGGER.error('The Gateway Is Not In Sync Mode') raise tokenfile = open(tokenfile, "w+") tokenfile.write(token) tokenfile.close() else: token = None bulbs = greenwave.grab_bulbs(host, token) add_devices(GreenwaveLight(device, host, token, GatewayData(host, token)) for device in bulbs.values())
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup Greenwave Reality Platform.""" import greenwavereality as greenwave import os host = config.get(CONF_HOST) tokenfile = hass.config.path('.greenwave') if config.get("version") == 3: if os.path.exists(tokenfile): tokenfile = open(tokenfile) token = tokenfile.read() tokenfile.close() else: token = greenwave.grab_token(host, 'hass', 'homeassistant') tokenfile = open(tokenfile, "w+") tokenfile.write(token) tokenfile.close() else: token = None doc = greenwave.grab_xml(host, token) add_devices(GreenwaveLight(device, host, token) for device in doc)