Exemple #1
0
class TestError(AioHTTPTestCase):
    async def get_application(self):
        return web.Application()

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

        # 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()

    @unittest_run_loop
    async def test_invalid_target_device(self):
        async def send_command_to_unknown_device():
            random_uuid = uuid4()
            return await self.meross_manager.async_execute_cmd(destination_device_uuid=str(random_uuid), method='GET',
                                                               namespace=Namespace.SYSTEM_ALL, payload={})

        with self.assertRaises(CommandTimeoutError):
            await send_command_to_unknown_device()

    @unittest_run_loop
    async def test_invalid_namespace(self):
        devs = self.meross_manager.find_devices(device_class=ToggleXMixin, online_status=OnlineStatus.ONLINE)
        if len(devs) < 1:
            self.skipTest("No available/online devices found to test. Skipping...")
        dev = devs[0]

        async def send_invalid_command_to_device(dev: BaseDevice):
            res = await self.meross_manager.async_execute_cmd(destination_device_uuid=dev.uuid, method='GET',
                                                              namespace=Namespace.HUB_MTS100_MODE, payload={})
            return res

        with self.assertRaises(CommandTimeoutError):
            await send_invalid_command_to_device(dev=dev)

    @unittest_run_loop
    async def test_invalid_payload(self):
        devs = self.meross_manager.find_devices(device_class=ToggleXMixin, online_status=OnlineStatus.ONLINE)
        if len(devs) < 1:
            self.skipTest("No available/online devices found to test. Skipping...")
        dev = devs[0]

        async def send_invalid_command_to_device(dev: BaseDevice):
            return await self.meross_manager.async_execute_cmd(destination_device_uuid=dev.uuid, method='SET',
                                                               namespace=Namespace.HUB_MTS100_MODE,
                                                               payload={'temperature': 'bar'})

        with self.assertRaises(CommandTimeoutError):
            await send_invalid_command_to_device(dev=dev)

    async def tearDownAsync(self):
        await self.meross_client.async_logout()
Exemple #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 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()
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()
Exemple #4
0
async def init_meross():
    # 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:
        log.info("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 = None
        for d in plugs:
            if d.name == "pm6006":
                dev = d
                break
        # The first time we play with a device, we must update its status
        await dev.async_update()
        log.info(dev)

        return manager, http_api_client, dev
Exemple #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 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()
Exemple #6
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 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()
Exemple #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()
Exemple #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)
Exemple #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()
Exemple #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)
Exemple #12
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()
Exemple #13
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
Exemple #14
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()
Exemple #15
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()
Exemple #16
0
class TestHub(AioHTTPTestCase):
    async def get_application(self):
        return web.Application()

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

        # 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.")
            return

        dev = self.test_devices[0]
        await dev.async_update()

    async def tearDownAsync(self):
        await self.meross_client.async_logout()
Exemple #17
0
    async def setUpAsync(self):
        self.meross_client = await MerossHttpClient.async_from_user_password(email=EMAIL, password=PASSWORD)

        # Look for a device to be used for this test
        manager = MerossManager(http_client=self.meross_client)
        await manager.async_init()
        devices = await manager.async_device_discovery()
        self.garage_devices = manager.find_devices(device_class=GarageOpenerMixin, online_status=OnlineStatus.ONLINE)
async def shutdown(email, password, id_plugs):
    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='mss425e') or manager.find_devices(device_type='mss425f')

    if len(plugs) > 0:
        plug = plugs[0]

        for id_plug in id_plugs:
            await plug.async_update()
            await asyncio.sleep(1)
            await plug.async_turn_off(channel=id_plug)
            await asyncio.sleep(1)
class TestPushNotificationHandler(AioHTTPTestCase):
    async def get_application(self):
        return web.Application()

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

        # 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=ToggleXMixin, 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_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()

    async def tearDownAsync(self):
        await self.meross_client.async_logout()
Exemple #20
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()
Exemple #21
0
    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
        manager = MerossManager(http_client=self.meross_client)
        await manager.async_init()
        devices = await manager.async_device_discovery()
        self.garage_devices = manager.find_devices(
            device_class=GarageOpenerMixin, online_status=OnlineStatus.ONLINE)
Exemple #22
0
    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
        manager = MerossManager(http_client=self.meross_client,
                                max_requests_per_second=2)
        await manager.async_init()
        devices = await manager.async_device_discovery()

        self.test_sensors = manager.find_devices(
            device_class=ElectricityMixin, online_status=OnlineStatus.ONLINE)
Exemple #23
0
    async def setUpAsync(self):
        self.meross_client = await MerossHttpClient.async_from_user_password(
            email=EMAIL, password=PASSWORD)

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

        # Update the states of all devices a first time
        concurrent_update = [d.async_update() for d in self.light_devices]
        await asyncio.gather(*concurrent_update)
Exemple #24
0
    async def setUpAsync(self):
        self.meross_client = await MerossHttpClient.async_from_user_password(
            email=EMAIL, password=PASSWORD)

        # Look for a device to be used for this test
        manager = MerossManager(http_client=self.meross_client)
        await manager.async_init()
        devices = await manager.async_device_discovery()
        toggle_devices = 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]
Exemple #25
0
    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
        manager = MerossManager(http_client=self.meross_client)
        await manager.async_init()
        devices = await manager.async_device_discovery()
        toggle_devices = 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]
Exemple #26
0
    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
        manager = MerossManager(http_client=self.meross_client)
        await manager.async_init()
        devices = await manager.async_device_discovery()
        self.light_devices = manager.find_devices(
            device_class=LightMixin, online_status=OnlineStatus.ONLINE)

        # Update the states of all devices a first time
        concurrent_update = [d.async_update() for d in self.light_devices]
        await asyncio.gather(*concurrent_update)
Exemple #27
0
async def main():
    if len(sys.argv) != 2:
        usage()

    file = sys.argv[1]

    email = os.environ.get('MEROSS_EMAIL')
    password = os.environ.get('MEROSS_PASSWORD')

    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()

    bulbs = manager.find_devices(device_type="msl120d")
    bulbs += manager.find_devices(device_type="msl120j")

    bulb_settings = read_bulb_settings_from_csv(file)

    for bulb in bulbs:
        this_bulb_settings = bulb_settings[bulb.name.lower()]

        if this_bulb_settings['onoff']:
            await bulb.async_update()
            await bulb.async_set_light_color(
                rgb=this_bulb_settings['rgb'],
                luminance=this_bulb_settings['luminance'])
        else:
            await bulb.async_update()
            await bulb.async_turn_off()

    manager.close()
    await http_api_client.async_logout()
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)
Exemple #29
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()
Exemple #30
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='mss310')

    if len(plugs) < 1:
        return
    else:
        dev = plugs[0]
        await dev.async_update()
        await dev.async_turn_on(channel=0)