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()
async def setUpAsync(self): # Setup the proxy self._proxy = ProxyManager(port=PROXY_PORT) self._proxy.start() _LOGGER.info("Proxy started") # Wait some time before next test-burst _LOGGER.info("Sleeping...") await asyncio.sleep(10) _LOGGER.info( "Allocating and configuring MerossManager to use the proxy") self.meross_client, self.requires_logout = await async_get_client() self.meross_client.set_http_proxy(f"http://localhost:{PROXY_PORT}") self.meross_manager = MerossManager(http_client=self.meross_client) self.meross_manager.set_proxy(proxy_type=socks.HTTP, proxy_addr="localhost", proxy_port=PROXY_PORT) await self.meross_manager.async_init() _LOGGER.info("Manager started") await self.meross_manager.async_device_discovery() self.test_devices = self.meross_manager.find_devices( device_class=ToggleXMixin, online_status=OnlineStatus.ONLINE) _LOGGER.info("Discovery ended. Test devices: %s", self.test_devices)
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()
def __init__(self, verbose=False): """ Initialize the object. verbose -- whether or not to enable verbose logging """ self.name = self.__class__.__name__ Adapter.__init__(self, 'meross-adapter', 'meross-adapter', verbose=verbose) self.manager = None self.pairing = False database = Database(self.package_name) if database.open(): config = database.load_config() if 'username' in config and len(config['username']) > 0 and \ 'password' in config and len(config['password']) > 0: self.manager = MerossManager( meross_email=config['username'], meross_password=config['password']) self.manager.register_event_handler(self.event_handler) self.manager.start() database.close() self.start_pairing()
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)
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()
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()
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)
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()
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()
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
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 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()
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()
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()
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 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
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 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()
def setUp(self): self.manager = MerossManager(meross_email=EMAIL, meross_password=PASSWORD) self.manager.start() # Retrieves the list of supported devices devices = self.manager.get_devices_by_type('mss310') if len(devices) > 0: self.device = devices[0] else: raise Exception("Could not find device mss310")
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()
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()
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)
def main(): print( "Welcome to the InfoGather software. This python script will gather some useful information about your " "Meross devices. All the collected information will be zipped into a zip archive. " "You could share such zip file with the developers to help them add support for your device. " "Although this utility won't collect your email/password, we recommend you to change " "your Meross account password to a temporary one before using this software. Once you are done, " "you can restore back your original password. By doing so, you are 100% sure you are not leaking any " "real password to the developers.") email = input("Please specify your meross email: ") email = email.strip() password = input("Please specify your meross password: "******"# Collecting devices via HTTP api...") devices = client.list_devices() l.info("DEVICE LISTING VIA HTTP: %s" % devices) except: print("An error occurred while retrieving Meross devices.") exit(1) print("# Starting manager...") manager.start() print("# Gathering info about supported devices...") devices = manager.get_supported_devices() for d in devices: describe_device(d, manager) print( "# OK. You can now play with the Meross official APP with your devices to trigger some actions. Hopefully" " this program will be able to collect necessary data to help the developers implement its support." ) print( "Once done, simply press ENTER and the program will stop gathering information and return." ) input("Press ENTER to stop recording data and exit") print("Collecting logs...") zipObj = ZipFile('data.zip', 'w') zipObj.write(ROOT_LOG_FILE) zipObj.write(INFO_LOG_FILE) zipObj.close() print( "A zipfile has been created containing the logs collected during this execution. " "It is located in {path}.".format(path=path.abspath(zipObj.filename))) print("Thanks for helping the Meross community!")
class SwitchControl: def __init__(self): # Initiates the Meross Cloud Manager. This is in charge of handling the communication with the remote endpoint self.manager = MerossManager(meross_email=EMAIL, meross_password=PASSWORD) # Starts the manager self.manager.start() self.smart_sw = self.manager.get_device_by_name("Living room lamp") """ Check if the smart switch is online (ie. is plugged into a socket) return - true if online, else false """ def checkOnline(self): if not self.smart_sw.online: return False else: return True """ Turn on the smart switch (ie turn on the kettle) return - true if it successfully turned on the switch, else false """ def turnOnKettle(self): if self.checkOnline(): channels = len(self.smart_sw.get_channels()) for i in range(0, channels): print("Turning on channel %d of %s" % (i, self.smart_sw.name)) self.smart_sw.turn_on_channel(i) return True else: return False """ Turn off the smart switch (ie turn off the kettle) return - true if it successfully turned off the switch, else false """ def turnOffKettle(self): if self.checkOnline(): channels = len(self.smart_sw.get_channels()) for i in range(0, channels): print("Turning off channel %d of %s" % (i, self.smart_sw.name)) self.smart_sw.turn_off_channel(i) return True else: return False
def setUp(self): self.counter = AtomicCounter(0) set_log_level(INFO, INFO) self.manager = MerossManager(meross_email=EMAIL, meross_password=PASSWORD) self.manager.start() # Retrieves the list of supported devices devices = self.manager.get_devices_by_type('mss425e') if len(devices) > 0: self.device = devices[0] else: raise Exception("Could not find device mss425e")
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)
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]
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()
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)