def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the myStrom Light platform.""" host = config.get(CONF_HOST) mac = config.get(CONF_MAC) name = config.get(CONF_NAME) bulb = MyStromBulb(host, mac) try: if bulb.get_status()["type"] != "rgblamp": _LOGGER.error("Device %s (%s) is not a myStrom bulb", host, mac) return except MyStromConnectionError: _LOGGER.warning("No route to device: %s", host) add_entities([MyStromLight(bulb, name)], True)
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the myStrom Light platform.""" from pymystrom.bulb import MyStromBulb from pymystrom.exceptions import MyStromConnectionError host = config.get(CONF_HOST) mac = config.get(CONF_MAC) name = config.get(CONF_NAME) bulb = MyStromBulb(host, mac) try: if bulb.get_status()['type'] != 'rgblamp': _LOGGER.error("Device %s (%s) is not a myStrom bulb", host, mac) return except MyStromConnectionError: _LOGGER.warning("No route to device: %s", host) add_entities([MyStromLight(bulb, name)], True)
def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the myStrom Light platform.""" from pymystrom.bulb import MyStromBulb from pymystrom.exceptions import MyStromConnectionError host = config.get(CONF_HOST) mac = config.get(CONF_MAC) name = config.get(CONF_NAME) bulb = MyStromBulb(host, mac) try: if bulb.get_status()['type'] != 'rgblamp': _LOGGER.error("Device %s (%s) is not a myStrom bulb", host, mac) return False except MyStromConnectionError: _LOGGER.warning("myStrom bulb not online") add_devices([MyStromLight(bulb, name)], True)
async def main(): """Sample code to work with a myStrom bulb.""" # Discover myStrom bulbs devices devices = await discover_devices() print(f"Found {len(devices)} bulb(s)") for device in devices: print(f" IP address: {device.host}, MAC address: {device.mac}") async with MyStromBulb(IP_ADDRESS, MAC_ADDRESS) as bulb: print("Get the details from the bulb...") await bulb.get_state() print("Power consumption:", bulb.consumption) print("Firmware:", bulb.firmware) print("Current state:", "off" if bulb.state is False else "on") print("Bulb will be switched on with their previous setting") await bulb.set_on() # print("Waiting for a couple of seconds...") await asyncio.sleep(2) print("Bulb will be set to white") await bulb.set_white() # Wait a few seconds to get a reading of the power consumption print("Waiting for a couple of seconds...") await asyncio.sleep(2) # Set transition time to 2 s await bulb.set_transition_time(2000) # Set to blue as HEX await bulb.set_color_hex("000000FF") await asyncio.sleep(3) # Set color as HSV (Hue, Saturation, Value) await bulb.set_color_hsv(0, 0, 100) await asyncio.sleep(3) # Test a fast flashing sequence print("Flash it for 10 seconds...") await bulb.set_flashing(10, [100, 50, 30], [200, 0, 71]) await bulb.set_off() # Show a sunrise within a minute print("Show a sunrise for 60 s") await bulb.set_sunrise(60) # Show a rainbow for 60 seconds print("Show a rainbow") await bulb.set_rainbow(60) # Reset transition time await bulb.set_transition_time(1000) # Shutdown the bulb await bulb.set_off()
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the myStrom light integration.""" host = config.get(CONF_HOST) mac = config.get(CONF_MAC) name = config.get(CONF_NAME) bulb = MyStromBulb(host, mac) try: await bulb.get_state() if bulb.bulb_type != "rgblamp": _LOGGER.error("Device %s (%s) is not a myStrom bulb", host, mac) return except MyStromConnectionError as err: _LOGGER.warning("No route to myStrom bulb: %s", host) raise PlatformNotReady() from err async_add_entities([MyStromLight(bulb, name, mac)], True)
async def async_setup_platform( hass: HomeAssistant, config: ConfigType, async_add_entities: AddEntitiesCallback, discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up the myStrom light integration.""" host = config.get(CONF_HOST) mac = config.get(CONF_MAC) name = config.get(CONF_NAME) bulb = MyStromBulb(host, mac) try: await bulb.get_state() if bulb.bulb_type not in ["rgblamp", "strip"]: _LOGGER.error( "Device %s (%s) is not a myStrom bulb nor myStrom LED Strip", host, mac) return except MyStromConnectionError as err: _LOGGER.warning("No route to myStrom bulb: %s", host) raise PlatformNotReady() from err async_add_entities([MyStromLight(bulb, name, mac)], True)
async def rainbow(ip, mac, time): """Let the buld change the color and show a rainbow.""" async with MyStromBulb(ip, mac) as bulb: await bulb.set_rainbow(time) await bulb.set_transition_time(1000)
async def flash(ip, mac, time): """Flash the bulb off.""" async with MyStromBulb(ip, mac) as bulb: await bulb.set_flashing(time, [100, 50, 30], [200, 0, 71])
async def off(ip, mac): """Switch the bulb off.""" async with MyStromBulb(ip, mac) as bulb: await bulb.set_off()
async def color(ip, mac, hue, saturation, value): """Switch the bulb on with the given color.""" async with MyStromBulb(ip, mac) as bulb: await bulb.set_color_hsv(hue, saturation, value)
async def on(ip, mac): """Switch the bulb on.""" async with MyStromBulb(ip, mac) as bulb: await bulb.set_color_hex("00FFFFFF")
def off(ip, mac): """Switch the bulb off.""" bulb = MyStromBulb(ip, mac) bulb.set_off()
def color(ip, mac, hue, saturation, value): """Switch the bulb on with the given color.""" bulb = MyStromBulb(ip, mac) bulb.set_color_hsv(hue, saturation, value)
def on(ip, mac): """Switch the bulb on.""" bulb = MyStromBulb(ip, mac) bulb.set_color_hex('000000FF')