Skip to content

Commit

Permalink
📒 add track local models
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Sep 8, 2021
1 parent 1679ce0 commit d9a2579
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
25 changes: 23 additions & 2 deletions custom_components/xiaomi_miot/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
MiotCloud,
MiCloudException,
)
from .core.utils import async_analytics_track_event

_LOGGER = logging.getLogger(__name__)
DEFAULT_INTERVAL = 30
Expand All @@ -50,20 +51,40 @@ async def check_miio_device(hass, user_input, errors):
device = MiioDevice(host, token)
info = await hass.async_add_executor_job(device.info)
except DeviceException:
device = None
info = None
errors['base'] = 'cannot_connect'
_LOGGER.debug('Xiaomi Miot config flow: %s', {
'user_input': user_input,
'miio_info': info,
'errors': errors,
})
model = ''
if info is not None:
if not user_input.get(CONF_MODEL):
user_input[CONF_MODEL] = str(info.model or '')
model = str(info.model or '')
user_input[CONF_MODEL] = model
user_input['miio_info'] = dict(info.raw or {})
miot_type = await MiotSpec.async_get_model_type(hass, user_input.get(CONF_MODEL))
miot_type = await MiotSpec.async_get_model_type(hass, model)
user_input['miot_type'] = miot_type
user_input['unique_did'] = format_mac(info.mac_address)
if miot_type and device:
try:
pms = [
{'did': 'miot', 'siid': 2, 'piid': 1},
{'did': 'miot', 'siid': 2, 'piid': 2},
{'did': 'miot', 'siid': 3, 'piid': 1},
]
results = device.get_properties(pms, property_getter='get_properties') or []
for prop in results:
if not isinstance(prop, dict):
continue
if prop.get('code') == 0:
# Collect supported models in LAN
await async_analytics_track_event('miot', 'local', model)
break
except DeviceException:
pass
return user_input


Expand Down
22 changes: 22 additions & 0 deletions custom_components/xiaomi_miot/core/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import time
import requests
from functools import partial


class RC4:
_idx = 0
Expand Down Expand Up @@ -39,3 +43,21 @@ def crypt(self, data):
def init1024(self):
self.crypt(bytes(1024))
return self


def analytics_track_event(event, action, label, value=0, node_id=''):
pms = {
'id': '1280294351',
'ei': '|'.join([event, action, label, f'{value}', node_id]),
'p': 'https://miot-spec.com',
't': 'Home Assistant',
'rnd': int(time.time() / 2.67),
}
url = 'https://ei.cnzz.com/stat.htm'
return requests.get(url, params=pms)


async def async_analytics_track_event(self, *args, **kwargs):
return await self.hass.async_add_executor_job(
partial(self.analytics_track_event, *args, **kwargs)
)

2 comments on commit d9a2579

@al-one
Copy link
Owner Author

@al-one al-one commented on d9a2579 Sep 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you integrate a device through a token, and it supports miot-spec in the local area network, the device model (like: brand.device.model) will be shared to https://ei.cnzz.com (a statistical website) for the purpose of In order to use local mode to integrate supported devices in the future. This is currently the only codes that will send your data (device model only) to a third-party website. Please rest assured that the component codes are all open source, and we will not collect any of your private data casually.


如果你通过token集成一个设备,并且它支持miot-spec在局域网,该设备型号(形如: brand.device.model)会被共享到https://ei.cnzz.com(一个统计网站),目的是以便日后使用本地模式去集成支持的设备。这是目前本插件唯一会发送你的数据(仅设备型号)到第三方网站的代码。请放心,本插件代码都是开源的,我们不会随便收集任何你的隐私数据。


def analytics_track_event(event, action, label, value=0, node_id=''):
pms = {
'id': '1280294351',
'ei': '|'.join([event, action, label, f'{value}', node_id]),
'p': 'https://miot-spec.com',
't': 'Home Assistant',
'rnd': int(time.time() / 2.67),
}
url = 'https://ei.cnzz.com/stat.htm'
return requests.get(url, params=pms)

References:

@al-one
Copy link
Owner Author

@al-one al-one commented on d9a2579 Sep 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.