Exemplo n.º 1
0
async def main():
    # Setup the HTTP client API from user-password
    http_api_client = await MerossHttpClient.async_from_user_password(
        email=EMAIL, password=PASSWORD)

    # Setup and start the device manager
    manager = MerossManager(http_client=http_api_client)
    await manager.async_init()

    # Retrieve all the MSS310 devices that are registered on this account
    await manager.async_device_discovery()
    plugs = manager.find_devices(device_type="mss210")

    if len(plugs) < 1:
        print("No MSS210 plugs found...")
    else:
        # Turn it on channel 0
        # Note that channel argument is optional for MSS310 as they only have one channel

        for dev in plugs:
            await check_device_schedule(dev)

    # Close the manager and logout from http_api
    manager.close()
    await http_api_client.async_logout()
Exemplo n.º 2
0
async def main():
    # Setup the HTTP client API from user-password
    http_api_client = await MerossHttpClient.async_from_user_password(email=EMAIL, password=PASSWORD)

    # Setup and start the device manager
    manager = MerossManager(http_client=http_api_client)
    await manager.async_init()

    # Retrieve all the devices that implement the electricity mixin
    await manager.async_device_discovery()
    devs = manager.find_devices(device_class=ElectricityMixin)

    if len(devs) < 1:
        # print("No electricity-capable device found...")
        print("")
    else:
        dev = devs[0]

        while True:
            # Read the electricity power/voltage/current
            instant_consumption = await dev.async_get_instant_metrics()
            # print(f"Current consumption data: {instant_consumption}")
            out = open("/tmp/instant_consumption.power", "w")
            out.write(f"{instant_consumption.power}")
            out.close()
            sleep(1)

    # Close the manager and logout from http_api
    manager.close()
    await http_api_client.async_logout()
Exemplo n.º 3
0
async def main():
    # Setup the HTTP client API from user-password
    http_api_client = await MerossHttpClient.async_from_user_password(
        email=EMAIL, password=PASSWORD)

    # Setup and start the device manager
    manager = MerossManager(http_client=http_api_client)
    await manager.async_init()

    # Retrieve all the MSS310 devices that are registered on this account
    await manager.async_device_discovery()
    plugs = manager.find_devices(device_type="mss310")

    if len(plugs) < 1:
        print("No MSS310 plugs found...")
    else:
        # Turn it on channel 0
        # Note that channel argument is optional for MSS310 as they only have one channel
        dev = plugs[0]
        print(f"Turning on {dev.name}...")
        await dev.async_turn_on(channel=0)
        print("Waiting a bit before turing it off")
        await asyncio.sleep(5)
        print(f"Turing off {dev.name}")
        await dev.async_turn_off(channel=0)

    # Close the manager and logout from http_api
    manager.close()
    await http_api_client.async_logout()
Exemplo n.º 4
0
async def main():
    # Setup the HTTP client API from user-password
    http_api_client = await MerossHttpClient.async_from_user_password(
        email=EMAIL, password=PASSWORD)

    # Setup and start the device manager
    manager = MerossManager(http_client=http_api_client)
    await manager.async_init()

    # Retrieve all the MS100 devices that are registered on this account
    await manager.async_device_discovery()
    sensors = manager.find_devices(device_type="ms100")

    if len(sensors) < 1:
        print("No MS100 plugs found...")
    else:
        dev = sensors[0]

        # Manually force and update to retrieve the latest temperature sensed from
        # the device. This ensures we get the most recent data and not a cached value
        await dev.async_update()

        # Access read cached data
        temp = dev.last_sampled_temperature
        humid = dev.last_sampled_humidity
        time = dev.last_sampled_time

        print(
            f"Current sampled data on {time.isoformat()}; Temperature={temp}°C, Humidity={humid}%"
        )
    # Close the manager and logout from http_api
    manager.close()
    await http_api_client.async_logout()
Exemplo n.º 5
0
async def main():
    # Setup the HTTP client API from user-password
    http_api_client = await MerossHttpClient.async_from_user_password(
        email=EMAIL, password=PASSWORD)

    # Setup and start the device manager
    manager = MerossManager(http_client=http_api_client)
    await manager.async_init()

    # Retrieve all the devices that implement the electricity mixin
    await manager.async_device_discovery()
    devs = manager.find_devices(device_class=ElectricityMixin)

    if len(devs) < 1:
        print("No electricity-capable device found...")
    else:
        dev = devs[0]

        # Update device status: this is needed only the very first time we play with this device (or if the
        #  connection goes down)
        await dev.async_update()

        # Read the electricity power/voltage/current
        instant_consumption = await dev.async_get_instant_metrics()
        print(f"Current consumption data: {instant_consumption}")

    # Close the manager and logout from http_api
    manager.close()
    await http_api_client.async_logout()
async def main():
    http_api_client = await MerossHttpClient.async_from_user_password(email=EMAIL, password=PASSWORD)
    manager = MerossManager(http_client=http_api_client)
    await manager.async_init()
    await manager.async_device_discovery()
    plugs = manager.find_devices(device_type=device_type)
    sleep(2)

    if len(plugs) < 1:
        print("No {device_type} plugs found...")
    else:
        plug_exsists = False
        x = 0
        for plug in plugs:
            if plug.name == device_name:
                plug_exsists = True
                plug_number = x
            x += 1
        if plug_exsists:
            dev = plugs[plug_number]
            await dev.async_turn_on(channel=0)
        else:
            print("Plug does not exsist")
    manager.close()
    await http_api_client.async_logout()
Exemplo n.º 7
0
async def main():
    # Setup the HTTP client API from user-password
    http_api_client = await MerossHttpClient.from_user_password(
        email="*****@*****.**", password="******")
    print("done1")
    # Setup and start the device manager
    manager = MerossManager(http_client=http_api_client)
    await manager.async_init()
    print("done2")
    # Retrieve all the MSS310 devices that are registered on this account
    await manager.async_device_discovery()
    plugs = manager.find_devices(device_type="mss310")
    print("done3")
    if len(plugs) < 1:
        print("No MSS310 plugs found...")
    else:
        # Turn it on channel 0
        # Note that channel argument is optional for MSS310 as they only have one channel
        dev = plugs[0]

        # The first time we play with a device, we must update its status
        await dev.async_update()

        # We can now start playing with that
        print(f"Turning on {dev.name}...")
        await dev.async_turn_on(channel=0)
        print("Waiting a bit before turing it off")
        await asyncio.sleep(5)
        print(f"Turing off {dev.name}")
        await dev.async_turn_off(channel=0)

    # Close the manager and logout from http_api
    manager.close()
    await http_api_client.async_logout()
Exemplo n.º 8
0
async def meross_action(name="phonecharger", action="off"):
    # Setup the HTTP client API from user-password
    http_api_client = await MerossHttpClient.async_from_user_password(email=EMAIL, password=PASSWORD)

    # Setup and start the device manager
    manager = MerossManager(http_client=http_api_client)
    await manager.async_init()

    # Retrieve all the MSS310 devices that are registered on this account
    await manager.async_device_discovery()
    devices = manager.find_devices(device_type="mss210")
    if len(devices) < 1:
        print("No MSS210 plugs found...")
    else:
        for plug in devices:
            if name in plug._name:
                # Turn it on channel 0
                # plug_name = plugs[0]._name = "bedroom charger"
                
                # Update device status: this is needed only the very first time we play with this device (or if the
                #  connection goes down)
                await plug.async_update()
                if action == "on":
                    print(f"Turning on {plug.name}...")
                    await plug.async_turn_on(channel=0)
                elif action == "off":
                    print(f"Turing off {plug.name}")
                    await plug.async_turn_off(channel=0)
    # Close the manager and logout from http_api
    manager.close()
    await http_api_client.async_logout()
Exemplo n.º 9
0
class TestHub(AioHTTPTestCase):
    async def get_application(self):
        return web.Application()

    async def setUpAsync(self):
        # Wait some time before next test-burst
        await asyncio.sleep(10)
        self.meross_client, self.requires_logout = await async_get_client()

        # Look for a device to be used for this test
        self.meross_manager = MerossManager(http_client=self.meross_client)
        await self.meross_manager.async_init()
        await self.meross_manager.async_device_discovery()
        self.test_devices = self.meross_manager.find_devices(
            device_class=HubDevice, online_status=OnlineStatus.ONLINE)

    @unittest_run_loop
    async def test_update(self):
        if len(self.test_devices) < 1:
            self.skipTest("No HUB device has been found to run this test.")

        dev = self.test_devices[0]
        print(f"Testing device {dev.name}")
        await dev.async_update()

    async def tearDownAsync(self):
        if self.requires_logout:
            await self.meross_client.async_logout()
        self.meross_manager.close()

        # Give a change to asyncio clean everything up
        await asyncio.sleep(1)
Exemplo n.º 10
0
async def main():
    http_api_client = await MerossHttpClient.async_from_user_password(
        email=EMAIL, password=PASSWORD)
    manager = MerossManager(http_client=http_api_client)
    await manager.async_init()
    await manager.async_device_discovery()
    plugs = manager.find_devices(device_type=device_type)
    sleep(2)

    if len(plugs) < 1:
        print("No {device_type} plugs found...")
    else:
        plug_exsists = False
        count = 0
        for plug in plugs:
            #print(f"- {plug.name} ({plug.type}): {plug.is_on}")
            if plug.name == device_name:
                plug_exsists = True
                plug_number = count
            count += 1
        if plug_exsists:
            dev = plugs[plug_number]
            await plug.async_update()
            if dev.is_on(channel=0):
                print('Turning OFF light')
                await dev.async_turn_off(channel=0)
            else:
                print('Turning ON light')
                await dev.async_turn_on(channel=0)
        else:
            print("Plug does not exsist")
    manager.close()
    await http_api_client.async_logout()
Exemplo n.º 11
0
class TestGarageOpener(AioHTTPTestCase):
    async def get_application(self):
        return web.Application()

    async def setUpAsync(self):
        # Wait some time before next test-burst
        await asyncio.sleep(10)
        self.meross_client, self.requires_logout = await async_get_client()

        # Look for a device to be used for this test
        self.meross_manager = MerossManager(http_client=self.meross_client)
        await self.meross_manager.async_init()
        devices = await self.meross_manager.async_device_discovery()
        self.garage_devices = self.meross_manager.find_devices(
            device_class=GarageOpenerMixin,
            online_status=OnlineStatus.ONLINE,
            device_type="msg100")

    @unittest_run_loop
    async def test_open_close(self):
        if len(self.garage_devices) < 1:
            self.skipTest(
                "Could not find any Garage Opener within the given set of devices. "
                "The test will be skipped")

        garage = self.garage_devices[0]
        print(f"Testing device {garage.name}")

        # Without a full update, the status will be NONE
        current_status = garage.get_is_open()
        self.assertIsNone(current_status)

        # Trigger the full update
        await garage.async_update()
        self.assertIsNotNone(garage.get_is_open())

        # Toggle
        is_open = garage.get_is_open()
        if is_open:
            await garage.async_close()
        else:
            await garage.async_open()
        await asyncio.sleep(40)
        self.assertEqual(garage.get_is_open(), not is_open)

        is_open = garage.get_is_open()
        if is_open:
            await garage.async_close()
        else:
            await garage.async_open()
        await asyncio.sleep(40)
        self.assertEqual(garage.get_is_open(), not is_open)

    async def tearDownAsync(self):
        if self.requires_logout:
            await self.meross_client.async_logout()
        self.meross_manager.close()

        # Give a change to asyncio clean everything up
        await asyncio.sleep(1)
Exemplo n.º 12
0
async def ask_meross():
    devices = []
    # Setup the HTTP client API from user-password
    http_api_client = await MerossHttpClient.async_from_user_password(
        email=EMAIL, password=PASSWORD)

    # Setup and start the device manager
    manager = MerossManager(http_client=http_api_client)
    await manager.async_init()

    await manager.async_device_discovery()
    devs = manager.find_devices(device_class=ElectricityMixin)

    if len(devs) < 1:
        print("No electricity-capable device found...")

    # Read the electricity power/voltage/current
    now = datetime.now()
    for dev in devs:
        for i in range(1):
            instant_consumption = await dev.async_get_instant_metrics()
            sleep(2)
            consumption_values.append(instant_consumption.power)

        devices.append({
            "type": "socket",
            "date": now.strftime("%d/%m/%Y, %H:%M:%S"),
            "name": dev.name,
            "consumption": instant_consumption.power
        })

    # Close the manager and logout from http_api
    manager.close()
    await http_api_client.async_logout()
    return devices
Exemplo n.º 13
0
    async def test_dev_push_notification(self):
        if self.test_device is None:
            self.skipTest("No ToggleX device has been found to run this test on.")
            return

        # Set the toggle device to ON state
        await self.test_device.async_turn_on()

        # Create a new manager
        new_meross_client = await MerossHttpClient.async_from_user_password(email=EMAIL, password=PASSWORD)
        m = None
        try:
            # Retrieve the same device with another manager
            m = MerossManager(http_client=new_meross_client)
            await m.async_init()
            await m.async_device_discovery()
            devs = m.find_devices(device_uuids=(self.test_device.uuid,))
            dev = devs[0]

            e = asyncio.Event()

            # Define the coroutine for handling push notification
            async def my_coro(namespace, data):
                e.set()

            dev.register_push_notification_handler_coroutine(my_coro)
            await self.test_device.async_turn_off()
            await asyncio.wait_for(e.wait(), 5.0)

        finally:
            if m is not None:
                m.close()
            await new_meross_client.async_logout()
Exemplo n.º 14
0
async def merossIotLightColorSkill(color=None):

    # Setup the HTTP client API from user-password
    http_api_client = await MerossHttpClient.async_from_user_password(email=MEROSS_USERNAME, password=MEROSS_PWD)

    # Setup and start the device manager
    manager = MerossManager(http_client=http_api_client)
    await manager.async_init()

    # Discover devices.
    await manager.async_device_discovery()

    # Print them
    # meross_devices = manager.find_devices()
    # print("I've found the following devices:")
    # for dev in meross_devices:
    #    print(f"- {dev.name} ({dev.type}): {dev.online_status}")

    # Retrieve the MSL120 devices that are registered on this account
    plugs = manager.find_devices(
        device_type="msl120d")  # , online_status=OnlineStatus.ONLINE)

    if len(plugs) < 1:
        # print("No online msl120d smart bulbs found...")
        speak("Sorry, no smart bulbs found or they are unresponsive")
    else:
        for plug in plugs:
            # Let's play with RGB colors. Note that not all light devices will support
            # rgb capabilities. For this reason, we first need to check for rgb before issuing
            # color commands.
            # dev = plugs[0]

            # Update device status: this is needed only the very first time we play with this device (or if the
            #  connection goes down)
            await plug.async_update()

            if not plug.get_supports_rgb():
                print("Unfortunately, this device does not support RGB...")
            else:
                # Check the current RGB color
                # current_color = dev.get_rgb_color()
                # print(f"Currently, device {dev.name} is set to color (RGB) = {current_color}")
                # Randomly chose a new color
                # rgb = randint(0, 255), randint(0, 255), randint(0, 255)
                # print(f"Chosen random color (R,G,B): {rgb}")
                if color:
                    await plug.async_set_light_color(luminance=100, rgb=color)
                else:
                    # White color
                    await plug.async_set_light_color(luminance=100, temperature=75)
                # print("Color changed!")

    # Close the manager and logout from http_api
    manager.close()
    await http_api_client.async_logout()
Exemplo n.º 15
0
class TestSensor(AioHTTPTestCase):
    async def get_application(self):
        return web.Application()

    async def setUpAsync(self):
        # Wait some time before next test-burst
        await asyncio.sleep(10)
        self.meross_client, self.requires_logout = await async_get_client()

        # Look for a device to be used for this test
        self.meross_manager = MerossManager(http_client=self.meross_client)
        await self.meross_manager.async_init()
        await self.meross_manager.async_device_discovery()
        self.test_devices = self.meross_manager.find_devices(
            device_class=Ms100Sensor, online_status=OnlineStatus.ONLINE)

    @unittest_run_loop
    async def test_temperature(self):
        if len(self.test_devices) < 1:
            self.skipTest("No sensor device has been found to run this test.")

        dev = self.test_devices[0]
        print(f"Testing device {dev.name}")
        await dev.async_update()

        self.assertIsNotNone(dev.last_sampled_temperature)
        self.assertIsNotNone(dev.last_sampled_time)

    @unittest_run_loop
    async def test_battery(self):
        if len(self.test_devices) < 1:
            self.skipTest("No sensor device has been found to run this test.")

        dev = self.test_devices[0]
        print(f"Testing device {dev.name}")
        await dev.async_update()
        res = await dev.async_get_battery_life()

        self.assertIsInstance(res, BatteryInfo)
        self.assertGreater(res.remaining_charge, 0)

    async def tearDownAsync(self):
        if self.requires_logout:
            await self.meross_client.async_logout()
        self.meross_manager.close()

        # Give a change to asyncio clean everything up
        await asyncio.sleep(1)
Exemplo n.º 16
0
    async def test_push_notification(self):
        if len(self.test_devices) < 1:
            self.skipTest("No valve device has been found to run this test.")
            return

        dev1 = self.test_devices[0]

        # Turn it on
        await dev1.async_turn_on()

        # Create a new manager
        new_meross_client = await MerossHttpClient.async_from_user_password(
            email=EMAIL, password=PASSWORD)
        m = None
        try:
            # Retrieve the same device with another manager
            m = MerossManager(http_client=new_meross_client)
            await m.async_init()
            await m.async_device_discovery()
            devs = m.find_devices(internal_ids=(dev1.internal_id, ))
            dev = devs[0]

            await dev.async_update()
            await dev1.async_update()

            # Set target temperature to a random state
            target = randint(dev.min_supported_temperature,
                             dev.max_supported_temperature)
            print(f"TARGET = {target}...")
            await dev1.async_set_target_temperature(temperature=target)

            # The manager that issues the command would immediately update the local state, so we can check
            # its update as soon as the command is issued.
            dev1_target_temp = dev1.target_temperature
            print(f"DEV1 = {dev1_target_temp}...")
            self.assertEqual(dev1_target_temp, target)

            # Wait a bit: give time for the push notification to get received on the other manager...
            await asyncio.sleep(5)
            # Make sure the other manager has received the push notification event
            dev_target_temp = dev.target_temperature
            print(f"DEV = {dev_target_temp}...")
            self.assertEqual(dev_target_temp, target)

        finally:
            if m is not None:
                m.close()
            await new_meross_client.async_logout()
Exemplo n.º 17
0
class TestUpdate(AioHTTPTestCase):
    async def get_application(self):
        return web.Application()

    async def setUpAsync(self):
        # Wait some time before next test-burst
        await asyncio.sleep(10)
        self.meross_client, self.requires_logout = await async_get_client()

        # Look for a device to be used for this test
        self.meross_manager = MerossManager(http_client=self.meross_client)
        await self.meross_manager.async_init()
        await self.meross_manager.async_device_discovery()
        self.test_devices = self.meross_manager.find_devices(device_class=(ToggleXMixin, LightMixin),
                                                             online_status=OnlineStatus.ONLINE)
        print(f"Test devices: {self.test_devices}")

    @unittest_run_loop
    async def test_update(self):
        if len(self.test_devices) < 1:
            self.skipTest("No device has been found to run this test UPDATE ALL on it.")

        # Turn off device to start from a clean state
        for d in self.test_devices:
            print(f"Testing device {d.name}")
            if isinstance(d, LightMixin):
                self.assertIsNone(d.get_rgb_color())
            elif isinstance(d, ToggleXMixin):
                self.assertIsNone(d.is_on())
            print(f"Executing update on device {d.name} ({d.type})")
            await d.async_update()

            if isinstance(d, LightMixin):
                self.assertIsNotNone(d.get_rgb_color())
            elif isinstance(d, ToggleXMixin):
                self.assertIsNotNone(d.is_on())

    async def tearDownAsync(self):
        if self.requires_logout:
            await self.meross_client.async_logout()
        self.meross_manager.close()

        # Give a change to asyncio clean everything up
        await asyncio.sleep(1)
Exemplo n.º 18
0
async def main():
    # Setup the HTTP client API from user-password
    http_api_client = await MerossHttpClient.async_from_user_password(
        email=EMAIL, password=PASSWORD)

    # Setup and start the device manager
    manager = MerossManager(http_client=http_api_client)
    await manager.async_init()

    # Retrieve all the devices that implement the garage-door opening mixin
    await manager.async_device_discovery()
    openers = manager.find_devices(device_class=GarageOpenerMixin)

    if len(openers) < 1:
        print("No garage opener found...")
    else:
        dev = openers[0]

        # Update device status: this is needed only the very first time we play with this device (or if the
        #  connection goes down)
        await dev.async_update()

        # Check current door status
        open_status = dev.get_is_open()
        if open_status:
            print(f"Door {dev.name} is open")
        else:
            print(f"Door {dev.name} is closed")

        # To open the door, uncomment the following:
        #print(f"Opening door {dev.name}...")
        #await dev.open(channel=0)
        #print("Door opened!")
        #
        # Wait a bit before closing it again
        #await asyncio.sleep(5)
        #
        #print(f"Closing door {dev.name}...")
        #await dev.close()
        # print(f"Door closed!")

    # Close the manager and logout from http_api
    manager.close()
    await http_api_client.async_logout()
Exemplo n.º 19
0
async def main():
    # Setup the HTTP client API from user-password
    http_api_client = await MerossHttpClient.async_from_user_password(
        email=EMAIL, password=PASSWORD)

    # Setup and start the device manager
    manager = MerossManager(http_client=http_api_client)
    await manager.async_init()

    # Retrieve all the mts100v3 devices that are registered on this account
    await manager.async_device_discovery()
    sensors = manager.find_devices(device_type="mts100v3")

    if len(sensors) < 1:
        print("No mts100v3 plugs found...")
    else:
        dev = sensors[0]

        # Manually force and update to retrieve the latest temperature sensed from
        # the device (this ensures we get the most recent value rather than a cached one)
        await dev.async_update()

        # Access read cached data
        on_off = dev.is_on()

        # Turn on the device if it's not on
        if not on_off:
            print(f"Device {dev.name} is off, turning it on...")
            await dev.async_turn_on()

        temp = await dev.async_get_temperature()
        print(f"Current ambient temperature = {temp} °C, "
              f"Target Temperature = {dev.target_temperature}, "
              f"mode = {dev.mode},"
              f"heating = {dev.is_heating}")

        # Randomly choose a temperature between min and max
        new_temp = randint(dev.min_supported_temperature,
                           dev.max_supported_temperature)
        print(f"Setting target temperature to {new_temp}")

    # Close the manager and logout from http_api
    manager.close()
    await http_api_client.async_logout()
Exemplo n.º 20
0
class TestSpray(AioHTTPTestCase):
    async def get_application(self):
        return web.Application()

    async def setUpAsync(self):
        # Wait some time before next test-burst
        await asyncio.sleep(10)
        self.meross_client, self.requires_logout = await async_get_client()

        # Look for a device to be used for this test
        self.meross_manager = MerossManager(http_client=self.meross_client)
        await self.meross_manager.async_init()
        devices = await self.meross_manager.async_device_discovery()
        self.test_devices = self.meross_manager.find_devices(
            device_class=SprayMixin, online_status=OnlineStatus.ONLINE)

    @unittest_run_loop
    async def test_spry(self):
        if len(self.test_devices) < 1:
            self.skipTest(
                "Could not find any SprayMixin within the given set of devices. "
                "The test will be skipped")

        dev = self.test_devices[0]
        print(f"Testing device {dev.name}")
        await dev.async_set_mode(mode=SprayMode.CONTINUOUS)
        self.assertEqual(dev.get_current_mode(), SprayMode.CONTINUOUS)

        await dev.async_set_mode(mode=SprayMode.INTERMITTENT)
        self.assertEqual(dev.get_current_mode(), SprayMode.INTERMITTENT)

        await dev.async_set_mode(mode=SprayMode.OFF)
        self.assertEqual(dev.get_current_mode(), SprayMode.OFF)

        await dev.async_update()

    async def tearDownAsync(self):
        if self.requires_logout:
            await self.meross_client.async_logout()
        self.meross_manager.close()

        # Give a change to asyncio clean everything up
        await asyncio.sleep(1)
Exemplo n.º 21
0
async def main():
    # Setup the HTTP client API from user-password
    http_api_client = await MerossHttpClient.async_from_user_password(
        email=EMAIL, password=PASSWORD)

    # Setup and start the device manager
    manager = MerossManager(http_client=http_api_client)
    await manager.async_init()

    # Retrieve the MSL120 devices that are registered on this account
    await manager.async_device_discovery()
    plugs = manager.find_devices(device_type="msl120",
                                 online_status=OnlineStatus.ONLINE)

    if len(plugs) < 1:
        print("No online msl120 smart bulbs found...")
    else:
        # Let's play with RGB colors. Note that not all light devices will support
        # rgb capabilities. For this reason, we first need to check for rgb before issuing
        # color commands.
        dev = plugs[0]

        # Update device status: this is needed only the very first time we play with this device (or if the
        #  connection goes down)
        await dev.async_update()
        if not dev.get_supports_rgb():
            print("Unfortunately, this device does not support RGB...")
        else:
            # Check the current RGB color
            current_color = dev.get_rgb_color()
            print(
                f"Currently, device {dev.name} is set to color (RGB) = {current_color}"
            )
            # Randomly chose a new color
            rgb = randint(0, 255), randint(0, 255), randint(0, 255)
            print(f"Chosen random color (R,G,B): {rgb}")
            await dev.async_set_light_color(rgb=rgb)
            print("Color changed!")

    # Close the manager and logout from http_api
    manager.close()
    await http_api_client.async_logout()
Exemplo n.º 22
0
async def merossasync(devicetype):

    with open(current_dir + 'meross-auth.json') as json_data_file:
        data = json.load(json_data_file)
        email = data["meross"]["email"]
        password = data["meross"]["password"]

    # Setup the HTTP client API from user-password
    http_api_client = await MerossHttpClient.async_from_user_password(
        email=email, password=password)

    # Setup and start the device manager
    manager = MerossManager(http_client=http_api_client)
    await manager.async_init()

    # Retrieve all the MS100 devices that are registered on this account
    await manager.async_device_discovery()
    sensors = manager.find_devices(device_type="ms100")

    if len(sensors) < 1:
        print("No MS100 plugs found...")
    else:
        dev = sensors[0]

        # Manually force and update to retrieve the latest temperature sensed from
        # the device. This ensures we get the most recent data and not a cached value
        await dev.async_update()

        # Access read cached data
        temp = dev.last_sampled_temperature
        humid = dev.last_sampled_humidity
        time = dev.last_sampled_time

        #writeMySQL(args, "meross" , None, 'temperature', temperature, None , "Celsius" )
        #writeMySQL(args, "meross" , None, 'humidity', humidity, None , "Humidity" )

        print(
            f"Current sampled data on {time.isoformat()}; Temperature={temp}°C, Humidity={humid}%"
        )
    # Close the manager and logout from http_api
    manager.close()
    await http_api_client.async_logout()
Exemplo n.º 23
0
async def main():
    # Setup the HTTP client API from user-password
    http_api_client = await MerossHttpClient.async_from_user_password(email=EMAIL, password=PASSWORD)

    # Setup and start the device manager
    manager = MerossManager(http_client=http_api_client)
    await manager.async_init()

    # Discover devices.
    await manager.async_device_discovery()
    meross_devices = manager.find_devices()

    # Print them
    print("I've found the following devices:")
    for dev in meross_devices:
        print(f"- {dev.name} ({dev.type}): {dev.online_status}")

    # Close the manager and logout from http_api
    manager.close()
    await http_api_client.async_logout()
Exemplo n.º 24
0
class TestTimeout(AioHTTPTestCase):
    async def get_application(self):
        return web.Application()

    async def setUpAsync(self):
        # Wait some time before next test-burst
        await asyncio.sleep(10)
        self.meross_client, self.requires_logout = await async_get_client()

        # Look for a device to be used for this test
        self.meross_manager = MerossManager(http_client=self.meross_client)
        await self.meross_manager.async_init()
        await self.meross_manager.async_device_discovery()
        self.test_devices = self.meross_manager.find_devices(
            device_class=SystemAllMixin, online_status=OnlineStatus.ONLINE)

    @unittest_run_loop
    async def test_short_timeout(self):
        if len(self.test_devices) < 1:
            self.skipTest("No device has been found to run this test.")

        # Select a device
        device: BaseDevice = self.test_devices[0]
        print(f"Selected device {device} for testing.")
        print(f"Default timeout was: {device.default_command_timeout}s.")

        # Set a very low timeout to trigger a command timeout error
        device.default_command_timeout = 0.01
        print(f"New timeout: {device.default_command_timeout}s.")

        # This should trigger a timeout error
        with self.assertRaises(CommandTimeoutError):
            await device.async_update()

    async def tearDownAsync(self):
        if self.requires_logout:
            await self.meross_client.async_logout()
        self.meross_manager.close()

        # Give a change to asyncio clean everything up
        await asyncio.sleep(1)
Exemplo n.º 25
0
class MerossWrapper():
    def __init__(self):
        self.EMAIL = os.environ.get('MEROSS_EMAIL')
        self.PASSWORD = os.environ.get('MEROSS_PASSWORD')

    async def connect(self):
        self.http_api_client = await MerossHttpClient.async_from_user_password(
                email=self.EMAIL,
                password=self.PASSWORD)

        self.manager = MerossManager(http_client=self.http_api_client, auto_reconnect=True)
        await self.manager.async_init()

        await self.manager.async_device_discovery()
        self.plugs = self.manager.find_devices()

        for plug in self.plugs:
            await plug.async_update()
            self.light_on = plug.is_on()

    def status(self):
        return "on" if self.light_on else "off"

    async def toggle(self):
        return await (self.off() if self.light_on else self.on())

    async def on(self):
        for plug in self.plugs:
            await plug.async_turn_on(channel=0)
        self.light_on = True
        return self.status()

    async def off(self):
        for plug in self.plugs:
            await plug.async_turn_off(channel=0)
        self.light_on = False
        return self.status()

    async def close(self):
        self.manager.close()
        await self.http_api_client.async_logout()
Exemplo n.º 26
0
    async def test_rgb_push_notification(self):
        # Make sure we have an RGB-capable available device
        rgb_capable = list(
            filter(lambda d: d.get_supports_rgb(), self.light_devices))
        if len(rgb_capable) < 1:
            self.skipTest(
                "Could not find any RGB-capable LightMixin within the given set of devices. "
                "The test will be skipped")
            return

        light = rgb_capable[0]

        # Create a new manager
        new_meross_client, requires_logout = await async_get_client()
        m = None
        try:
            # Retrieve the same device with another manager
            m = MerossManager(http_client=new_meross_client)
            await m.async_init()
            await m.async_device_discovery()
            devs = m.find_devices(device_uuids=(light.uuid, ))
            dev = devs[0]

            await dev.async_update()

            # Set RGB color to known state
            r = await light.async_set_light_color(rgb=(255, 0, 0))
            await asyncio.sleep(2)

            # Turn on the device
            r = await light.async_set_light_color(rgb=(0, 255, 0))

            # Wait a bit and make sure the other manager received the push notification
            await asyncio.sleep(10)
            self.assertEqual(light.get_rgb_color(), (0, 255, 0))
            self.assertEqual(dev.get_rgb_color(), (0, 255, 0))
        finally:
            if m is not None:
                m.close()
            if requires_logout:
                await new_meross_client.async_logout()
Exemplo n.º 27
0
    async def test_toggle_push_notification(self):
        if self.test_device is None:
            self.skipTest(
                "No ToggleX device has been found to run this test on.")
            return

        # Create a new manager
        new_meross_client = await MerossHttpClient.async_from_user_password(
            email=EMAIL, password=PASSWORD)
        m = None
        try:
            # Retrieve the same device with another manager
            m = MerossManager(http_client=new_meross_client)
            await m.async_init()
            await m.async_device_discovery()
            devs = m.find_devices(device_uuids=(self.test_device.uuid, ))
            dev = devs[0]

            # Turn off device to start from a clean state
            r = await self.test_device.async_turn_off()
            await asyncio.sleep(2)

            # Turn on the device
            r = await self.test_device.async_turn_on()
            # Wait a bit and make sure the other manager received the push notification
            await asyncio.sleep(2)
            self.assertTrue(self.test_device.is_on())
            self.assertTrue(dev.is_on())

            # Turn off the device
            await asyncio.sleep(1)
            r = await self.test_device.async_turn_off()
            # Wait a bit and make sure the other manager received the push notification
            await asyncio.sleep(2)
            self.assertFalse(self.test_device.is_on())
            self.assertFalse(dev.is_on())

        finally:
            if m is not None:
                m.close()
            await new_meross_client.async_logout()
Exemplo n.º 28
0
async def main(email: str = config.MEROSS_EMAIL,
               password: str = config.MEROSS_PASSWORD):
    """Set the lights to the next bin colour"""
    # code smell but meh
    from bindicator import bins

    # Setup the HTTP client API from user-password
    http_api_client = await MerossHttpClient.async_from_user_password(
        email=email, password=password)

    # Setup and start the device manager
    manager = MerossManager(http_client=http_api_client,
                            over_limit_threshold_percentage=1000)
    await manager.async_init()

    # Retrieve all the MSS310 devices that are registered on this account
    # Discover devices.
    await manager.async_device_discovery()
    meross_devices = manager.find_devices()

    # Print them
    print("I've found the following devices:")
    for dev in meross_devices:
        print(f"- {dev.name} ({dev.type}): {dev.online_status}")
        # down and dirty
        if dev.name.startswith("Garage Bulb"):
            ix = int(dev.name[-1]) - 1
            new_col = bins.NEXT_BINS[ix]
            await dev.async_update()
            # Check the current RGB color
            current_color = dev.get_rgb_color()
            print(f"Device {dev.name} set to RGB {current_color}")
            # set to next bins colour
            print(f"Chosen random color (R,G,B): {new_col}")
            await dev.async_set_light_color(rgb=new_col.value)
            print("Color changed!")

    # Close the manager and logout from http_api
    manager.close()
    await http_api_client.async_logout()
Exemplo n.º 29
0
async def merossIotToggleSkill(mode):
    # Setup the HTTP client API from user-password
    http_api_client = await MerossHttpClient.async_from_user_password(email=MEROSS_USERNAME, password=MEROSS_PWD)

    # Setup and start the device manager
    manager = MerossManager(http_client=http_api_client)
    await manager.async_init()

    # Retrieve all the MSS310 devices that are registered on this account
    await manager.async_device_discovery()
    plugs = manager.find_devices(device_type="msl120d")

    if len(plugs) < 1:
        # print("No msl120d bulbs found...")
        speak("Sorry, no smart bulbs found or they are unresponsive")
    else:
        for plug in plugs:
            # Turn it on channel 0
            # Note that channel argument is optional for MSS310 as they only have one channel
            # dev = plugs[0]

            # Update device status: this is needed only the very first time we play with this device (or if the
            #  connection goes down)
            await plug.async_update()

            if mode == "turnon":
                print(f"Turning on {plug.name}...")
                await plug.async_turn_on(channel=0)
            # print("Waiting a bit before turing it off")
            # await asyncio.sleep(5)
            elif mode == "turnoff":
                print(f"Turing off {plug.name}")
                await plug.async_turn_off(channel=0)

    # Close the manager and logout from http_api
    manager.close()
    await http_api_client.async_logout()
Exemplo n.º 30
0
class TestConsumptionX(AioHTTPTestCase):
    async def get_application(self):
        return web.Application()

    async def setUpAsync(self):
        # Wait some time before next test-burst
        await asyncio.sleep(10)
        self.meross_client, self.requires_logout = await async_get_client()

        # Look for a device to be used for this test
        self.meross_manager = MerossManager(http_client=self.meross_client)
        await self.meross_manager.async_init()
        devices = await self.meross_manager.async_device_discovery()
        toggle_devices = self.meross_manager.find_devices(
            device_class=ConsumptionXMixin, online_status=OnlineStatus.ONLINE)

        if len(toggle_devices) < 1:
            self.test_device = None
        else:
            self.test_device = toggle_devices[0]

    @unittest_run_loop
    async def test_consumptionx_local_state(self):
        if self.test_device is None:
            self.skipTest(
                "No ConsumptionX device has been found to run this test on.")
        print(f"Testing device {self.test_device.name}")
        r = await self.test_device.async_get_daily_power_consumption()
        self.assertGreater(len(r), 1)

    async def tearDownAsync(self):
        if self.requires_logout:
            await self.meross_client.async_logout()
        self.meross_manager.close()

        # Give a change to asyncio clean everything up
        await asyncio.sleep(1)