HTTP Client

class meross_iot.http_api.MerossHttpClient(cloud_credentials: MerossCloudCreds, http_proxy: str | None = None, ua_header: str = 'MerossIOT/0.0.0', app_type: str = 'MerossIOT', app_version: str = '0.0.0', log_identifier: str = '083a96ad9eabe93982a6e978e038243c2dd7a2-6d87-4253-b789-a29c6c05c871')

Utility class for dealing with Meross HTTP API. This class simplifies the usage of the Meross HTTP API providing login, logout and device listing API.

async classmethod async_from_cloud_creds(creds: MerossCloudCreds, http_proxy: str | None = None, ua_header: str = 'MerossIOT/0.0.0', app_type: str = 'MerossIOT', app_version: str = '0.0.0', log_identifier: str = '083a96ad9eabe93982a6e978e038243c2dd7a2-6d87-4253-b789-a29c6c05c871', *args, **kwargs) MerossHttpClient

Build a MerossIot API client using the provided cloud-credentials object. :param creds: CloudCredentials object to build the client from :param http_proxy: HTTP proxy to use. When none, no proxy will be used. Defaults to None. :param ua_header: User agent headers to send alongside the various requests. The default value is auto-generated by the library. :param app_type: String used to discriminate the app type. The default value is auto-generated by the library. :param app_version: String used to discriminate the app version. The default value is auto-generated by the library. :param log_identifier: String used to log the app client usage. The default value is auto-generated by the library. :return:

async classmethod async_from_user_password(api_base_url: str, email: str, password: str, http_proxy: str = None, ua_header: str = 'MerossIOT/0.0.0', app_type: str = 'MerossIOT', app_version: str = '0.0.0', log_identifier: str = '083a96ad9eabe93982a6e978e038243c2dd7a2-6d87-4253-b789-a29c6c05c871', auto_retry_on_bad_domain: bool = True, mfa_code: string = None, *args, **kwargs) MerossHttpClient

Builds a MerossHttpClient using username/password combination. In any case, the login will generate a token, which might expire at any time.

Parameters:
  • api_base_url – Https base endpoint to use for API calls. It should be one of “https://iotx-eu.meross.com”, “https://iotx-ap.meross.com” or “https://iotx-us.meross.com”, based on your public IP region.,

  • email – Meross account email

  • password – Meross account password

  • http_proxy – Optional http proxy to use when issuing the requests

  • app_type – App Type header parameter to use

  • app_version – App Version header parameter to use

  • log_identifier – Log identifier to use

  • auto_retry_on_bad_domain – when set, it enables auto-retry when BadDomain exception occurs.

  • mfa_code – multi-factor authentication code (optional)

Returns:

an instance of MerossHttpClient

async async_invalidate_credentials(creds: MerossCloudCreds)

Class method used to invalidate credentials without logging in with a full MerossHttpClient.

Parameters:

credsMerossCloudCredentials as returned by async_login() or async_from_user_password()

Returns:

API response data

async async_list_devices(*args, **kwargs) List[HttpDeviceInfo]

Asks to the HTTP api to list the Meross device belonging to the given user account.

Returns:

a list of HttpDeviceInfo

async async_list_hub_subdevices(hub_id: str, *args, **kwargs) List[HttpSubdeviceInfo]

Returns the sub-devices associated to the given hub.

Parameters:

hub_id – Meross native UUID of the HUB

Returns:

a list of HttpSubdeviceInfo

async classmethod async_login(api_base_url: str, email: str, password: str, creds_env_var_name: str = '__MEROSS_CREDS', http_proxy: str | None = None, ua_header: str = 'MerossIOT/0.0.0', app_type: str = 'MerossIOT', app_version: str = '0.0.0', log_identifier: str = '083a96ad9eabe93982a6e978e038243c2dd7a2-6d87-4253-b789-a29c6c05c871', country_code: str = 'us', agree_to_terms: int = 0, mfa_code: str | None = None, stats_counter: HttpStatsCounter | None = None, auto_retry_on_bad_domain: bool = True, *args, **kwargs) MerossCloudCreds

Performs the login against the Meross HTTP endpoint. This api returns a MerossCloudCreds object, which contains the API endpoint, the mqtt endpoint and the authorization token to use the various API/MQTT services. Be cautious when invoking this API: asking for too many tokens as the Meross HTTP API might refuse to issue more tokens. Instead, you should keep using the same issued token when possible, possibly storing it across sessions. When you are done using a specific token, be sure to invoke logout to invalidate it.

Parameters:
  • api_base_url – Meross API base url.

  • email – Meross account email

  • password – Meross account password

  • creds_env_var_name – If set, indicate which env variables stores such credentials

  • http_proxy – Optional http proxy to use when to performing the request

  • ua_header – User Agent header to use when issuing the HTTP request

  • stats_counter – Stats counter object

  • app_type – App Type header parameter to use

  • app_version – App Version header parameter to use

  • country_code – (experimental) The country code you are connecting from

  • agree_to_terms – (optional) if 1 means we agree, if 0 or omitted, means we do not agree to terms

  • mfa_code – (optional) MFA code

  • auto_retry_on_bad_domain – when set, tells the library to retry the login when BadDomain occurs, osing the right domain value returned by the initial operation.

Returns:

a MerossCloudCreds object

async async_logout(*args, **kwargs)

Invalidates the credentials stored in this object.

Returns:

API response data

property cloud_credentials: MerossCloudCreds

Returns the meross credentials returned by the the HTTP Api :return: