async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the Midea lan service and query appliances.""" from msmart.device import air_conditioning_device as ac device_ip = config.get(CONF_HOST) device_id = config.get(CONF_ID) device_token = config.get(CONF_TOKEN) device_k1 = config.get(CONF_K1) device_port = config.get(CONF_PORT) prompt_tone = config.get(CONF_PROMPT_TONE) temp_step = config.get(CONF_TEMP_STEP) include_off_as_state = config.get(CONF_INCLUDE_OFF_AS_STATE) use_fan_only_workaround = config.get(CONF_USE_FAN_ONLY_WORKAROUND) keep_last_known_online_state = config.get( CONF_KEEP_LAST_KNOWN_ONLINE_STATE) device = ac(device_ip, int(device_id), device_port) if device_token and device_k1: device.authenticate(device_k1, device_token) # device = client.setup() device.prompt_tone = prompt_tone device.keep_last_known_online_state = keep_last_known_online_state entities = [] entities.append( MideaClimateACDevice(hass, device, temp_step, include_off_as_state, use_fan_only_workaround)) async_add_entities(entities)
async def support_test(self, account, password): if self.version == 3: _device = await self.support_testv3(self, account, password) else: _device = ac(self.ip, self.id, self.port) if self.type == 'ac': _device.refresh() _LOGGER.debug("{}".format(_device)) self.support = _device.support return self
async def support_testv3(self, account, password): _device = ac(self.ip, self.id, self.port) for udpid in [ get_udpid(self.id.to_bytes(6, 'little')), get_udpid(self.id.to_bytes(6, 'big')) ]: token, key = gettoken(udpid, account, password) auth = _device.authenticate(key, token) if auth: self.token, self.key = token, key return _device return _device
from msmart.device import air_conditioning_device as ac import logging import time logging.basicConfig(level=logging.DEBUG) # first take device's ip and id, port is generally 6444 # pip3 install msmart; midea-discover device = ac('YOUR_AC_IP', int('YOUR_AC_ID'), 6444) # If the device is using protocol 3 (aka 8370) # you must authenticate with device's k1 and token. # adb logcat | grep doKeyAgree device.authenticate('YOUR_AC_K1', 'YOUR_AC_TOKEN') # Refresh the object with the actual state by querying it device.refresh() print({ 'id': device.id, 'name': device.ip, 'power_state': device.power_state, 'prompt_tone': device.prompt_tone, 'target_temperature': device.target_temperature, 'operational_mode': device.operational_mode, 'fan_speed': device.fan_speed, 'swing_mode': device.swing_mode, 'eco_mode': device.eco_mode, 'turbo_mode': device.turbo_mode, 'indoor_temperature': device.indoor_temperature, 'outdoor_temperature': device.outdoor_temperature }) # Set the state of the device and