1 """Support for Greenwave Reality (TCP Connected) lights."""
3 from __future__
import annotations
5 from datetime
import timedelta
10 import greenwavereality
as greenwave
11 import voluptuous
as vol
15 PLATFORM_SCHEMA
as LIGHT_PLATFORM_SCHEMA,
26 _LOGGER = logging.getLogger(__name__)
28 CONF_VERSION =
"version"
30 PLATFORM_SCHEMA = LIGHT_PLATFORM_SCHEMA.extend(
31 {vol.Required(CONF_HOST): cv.string, vol.Required(CONF_VERSION): cv.positive_int}
40 add_entities: AddEntitiesCallback,
41 discovery_info: DiscoveryInfoType |
None =
None,
43 """Set up the Greenwave Reality Platform."""
44 host = config.get(CONF_HOST)
45 tokenfilename = hass.config.path(
".greenwave")
46 if config.get(CONF_VERSION) == 3:
47 if os.path.exists(tokenfilename):
48 with open(tokenfilename, encoding=
"utf8")
as tokenfile:
49 token = tokenfile.read()
52 token = greenwave.grab_token(host,
"hass",
"homeassistant")
53 except PermissionError:
54 _LOGGER.error(
"The Gateway Is Not In Sync Mode")
56 with open(tokenfilename,
"w+", encoding=
"utf8")
as tokenfile:
57 tokenfile.write(token)
60 bulbs = greenwave.grab_bulbs(host, token)
63 for device
in bulbs.values()
68 """Representation of an Greenwave Reality Light."""
70 _attr_color_mode = ColorMode.BRIGHTNESS
71 _attr_supported_color_modes = {ColorMode.BRIGHTNESS}
73 def __init__(self, light, host, token, gatewaydata):
74 """Initialize a Greenwave Reality Light."""
86 """Return true if light is on."""
90 """Instruct the light to turn on."""
91 temp_brightness =
int((kwargs.get(ATTR_BRIGHTNESS, 255) / 255) * 100)
92 greenwave.set_brightness(self.
_host_host, self.
_did_did, temp_brightness, self.
_token_token)
96 """Instruct the light to turn off."""
100 """Fetch new state data for this light."""
111 """Handle Gateway data and limit updates."""
114 """Initialize the data object."""
117 self.
_greenwave_greenwave = greenwave.grab_bulbs(host, token)
121 """Return Gateway API object."""
124 @Throttle(MIN_TIME_BETWEEN_UPDATES)
126 """Get the latest data from the gateway."""
def __init__(self, host, token)
None turn_off(self, **Any kwargs)
None turn_on(self, **Any kwargs)
def __init__(self, light, host, token, gatewaydata)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)
None open(self, **Any kwargs)