Skip to content

Commit

Permalink
Add the method to enable Telnet.
Browse files Browse the repository at this point in the history
  • Loading branch information
niceboy committed Jun 5, 2021
1 parent 84c1c71 commit 2b6e792
Show file tree
Hide file tree
Showing 32 changed files with 126 additions and 11 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ Gateway support **Zigbee 3**.

This integration was based on the development of <a href=https://github.com/AlexxIT/XiaomiGateway3/>@AlexxIT</a>, Thanks Alex.

**ATTENTION:** The component **only works on modified firmware (M2) or the gateway which enabled telnet . **
**ATTENTION:** The component **only works on modified firmware (M2) or the gateway which enabled telnet.**

To flash modified firmware to M2, please use <a href="https://github.com/niceboygithub/AqaraM1SM2fw/raw/main/tools/aqaragateway.exe"> AqaraGateway.exe </a> to flash. Need to open the case of gateway and wired out the UART.
For Gateway M2, to flash modified firmware to M2, please use <a href="https://github.com/niceboygithub/AqaraM1SM2fw/raw/main/tools/aqaragateway.exe"> AqaraGateway.exe </a> to flash customize firmware. Need to open the case of gateway and wired out the UART.

For M1S CN and AirCondition P3, you can use <a href="https://gist.github.com/zvldz/1bd6b21539f84339c218f9427e022709"> custom open telnet command </a> way 2 or way 3 to enable telnet in *Mi Home mode*, then flash modification firmwares to <a href="https://github.com/niceboygithub/AqaraM1SM2fw/tree/main/modified/M1S"> M1S </a>, <a href="https://github.com/niceboygithub/AqaraM1SM2fw/tree/main/modified/P3/3.0.7_0007.0515"> P3 </a> or copy pubic mosquitto to /data/bin. No need to open the case of gateway.
For Gateway M1S CN, AirCondition P3, Smart Hub H1, please switch to **Mija Home mode**, and [get the token](https://github.com/piotrmachowski/xiaomi-cloud-tokens-extractor). Then install this integration by HACS. After installation, add this componment via GUI integration of Home Assistant. Or you can use <a href="https://gist.github.com/zvldz/1bd6b21539f84339c218f9427e022709"> custom open telnet command </a> way 2 or way 3 to enable telnet in *Mija Home mode*, then flash modification firmwares to <a href="https://github.com/niceboygithub/AqaraM1SM2fw/tree/main/modified/M1S"> M1S </a>, <a href="https://github.com/niceboygithub/AqaraM1SM2fw/tree/main/modified/P3"> P3 </a> if you want use them in Aqara Home.No need to open the case of gateway.

After telnet to gateway via putty, there are two methods (Flash or Not) to enable telnet and public mqtt.

Expand All @@ -35,7 +35,7 @@ Then restart gateway by reboot command.
cd /tmp
wget -O /tmp/curl "http://master.dl.sourceforge.net/project/mgl03/bin/curl?viasf=1"
chmod a+x /tmp/curl
/tmp/curl -s -k -L -o /tmp/linux.bin https://github.com/niceboygithub/AqaraM1SM2fw/blob/main/modified/M1S/3.2.4_0014.0520_mi_fw_ver_3.1.3_0011/rootfs_3.2.4_0014.0520_mi_fw_ver_3.1.3_0011_modification.bin
/tmp/curl -s -k -L -o /tmp/linux.bin https://github.com/niceboygithub/AqaraM1SM2fw/blob/main/original/M1S/3.2.4_0014.0520_mi_fw_ver_3.1.3_0011/linux_3.2.4_0014.0520_mi_fw_ver_3.1.3_0011.bin
fw_update /tmp/linux.bin
/tmp/curl -s -k -L -o /tmp/rootfs.bin https://github.com/niceboygithub/AqaraM1SM2fw/blob/main/modified/M1S/3.2.4_0014.0520_mi_fw_ver_3.1.3_0011/rootfs_3.2.4_0014.0520_mi_fw_ver_3.1.3_0011_modification.bin
fw_update /tmp/rootfs.bin
Expand Down
9 changes: 8 additions & 1 deletion custom_components/aqara_gateway/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
OptionsFlow,
ConfigEntry
)
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_TOKEN
from homeassistant.core import callback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.util.network import is_ip_address
Expand All @@ -33,6 +33,7 @@ def __init__(self):
"""Initialize flow."""
self._host: Optional[str] = None
self._password: Optional[str] = None
self._token: Optional[str] = None
self._model: Optional[str] = None
self._device_info: Optional[str] = None

Expand All @@ -52,6 +53,8 @@ async def async_step_user(
self._set_user_input(user_input)
if not is_ip_address(self._host):
return self.async_abort(reason="connection_error")
if self._token and self._model in ('m1s', 'p3', 'h1'):
Utils.enable_telnet(self._host, self._token)
ret = gateway.is_aqaragateway(self._host,
self._password,
self._model)
Expand All @@ -71,6 +74,8 @@ async def async_step_user(
default=self._host or vol.UNDEFINED)] = str
fields[vol.Optional(CONF_PASSWORD,
default=self._password or vol.UNDEFINED)] = str
fields[vol.Optional(CONF_TOKEN,
default=self._token or vol.UNDEFINED)] = str
fields[vol.Optional(CONF_MODEL,
default=self._model or 'm1s')] = vol.In(
OPT_DEVICE_NAME)
Expand Down Expand Up @@ -100,6 +105,7 @@ def _set_user_input(self, user_input):
return
self._host = user_input.get(CONF_HOST, "")
self._password = user_input.get(CONF_PASSWORD, "")
self._token = user_input.get(CONF_TOKEN, "")
self._model = user_input.get(CONF_MODEL, "")

async def _async_add(self, user_input):
Expand All @@ -110,6 +116,7 @@ async def _async_add(self, user_input):
data={
CONF_HOST: self._host,
CONF_PASSWORD: self._password,
CONF_TOKEN: self._token,
CONF_MODEL: self._model,
CONF_NOFFLINE: True
},
Expand Down
1 change: 1 addition & 0 deletions custom_components/aqara_gateway/core/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

OPT_DEVICE_NAME = {
'g2h': "Aqara Camera Hub G2H",
'h1': "Aqara Smart Hub H1",
'p3': "Aqara AirCondition P3",
'm1s': "Aqara Gateway M1S",
'm2': "Aqara Gateway M2"
Expand Down
53 changes: 52 additions & 1 deletion custom_components/aqara_gateway/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
from typing import Optional

from aiohttp import web
from miio import Device, DeviceException
from homeassistant.components.http import HomeAssistantView
from homeassistant.helpers.device_registry import DeviceRegistry
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.exceptions import PlatformNotReady


# https://github.com/Koenkk/zigbee-herdsman-converters/blob/master/devices.js#L390
Expand Down Expand Up @@ -295,7 +297,6 @@
}, {
# motion sensor
'lumi.sensor_motion': ["Xiaomi", "Motion Sensor", "RTCGQ01LM"],
'lumi.motion.agl04': ["Aqara", "Precision Motion Sensor", "RTCGQ13LM"],
'params': [
['3.1.85', None, 'motion', 'binary_sensor'],
['8.0.2001', 'battery', 'battery', 'sensor'],
Expand Down Expand Up @@ -470,6 +471,33 @@
['3.2', '3.2', 'power', 'sensor'],
# ['5.7', '5.7', 'voltage', 'sensor'],
]
}, {
'lumi.motion.agl04': ["Aqara", "Precision Motion Sensor", "RTCGQ13LM"],
'mi_spec': [
[None, None, 'motion', 'binary_sensor'],
['3.1', '3.1', 'battery', 'sensor'],
['4.1', None, 'motion: 1', None],
]
}, {
'lumi.switch.b1lc04': ["Aqara", "Single Wall Switch E1", "QBKG38LM"],
'mi_spec': [
['2.1', '2.1', 'switch', 'switch'],
['6.1', None, 'button: 1', None],
['6.2', None, 'button: 2', None],
[None, None, 'action', 'sensor'],
]
}, {
'lumi.switch.b2lc04': ["Aqara", "Double Wall Switch E1", "QBKG39LM"],
'mi_spec': [
['2.1', '2.1', 'channel 1', 'switch'],
['3.1', '3.1', 'channel 2', 'switch'],
['7.1', None, 'button_1: 1', None],
['7.2', None, 'button_1: 2', None],
['8.1', None, 'button_2: 1', None],
['8.2', None, 'button_2: 2', None],
['9.1', None, 'button_both: 4', None],
[None, None, 'action', 'sensor'],
]
}]

GLOBAL_PROP = {
Expand Down Expand Up @@ -670,6 +698,29 @@ def get_info_store_path(model: str) -> Optional[str]:
return '/mnt/config'
return '/data'

@staticmethod
def enable_telnet(host, token):
""" enable telnet in gateway which using miot """
try:
miio_device = Device(host, token)
device_info = miio_device.info()
if device_info.model:
model = device_info.model
_LOGGER.info(
"%s %s %s detected",
model,
device_info.firmware_version,
device_info.hardware_version,
)
ret = miio_device.raw_command(
"set_ip_info",
{"ssid":"\"\"","pswd":"123123 ; passwd -d admin ; echo enable > /sys/class/tty/tty/enable; telnetd"}
)
if 'ok' not in ret:
raise PlatformNotReady
except DeviceException:
raise PlatformNotReady


class AqaraGatewayDebug(logging.Handler, HomeAssistantView):
# pylint: disable=abstract-method, arguments-differ
Expand Down
2 changes: 2 additions & 0 deletions custom_components/aqara_gateway/translations/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"data": {
"host": "\u0410\u0434\u0440\u0435\u0441",
"password": "Password",
"token": "Token",
"model": "Model",
"debug": "Debug",
"noffline": "Ignore Offline message"
Expand All @@ -31,6 +32,7 @@
"data": {
"host": "Host",
"password": "Password",
"token": "Token",
"model": "Model",
"stats": "Stats",
"debug": "Debug",
Expand Down
2 changes: 2 additions & 0 deletions custom_components/aqara_gateway/translations/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"data": {
"host": "Amfitri\u00f3",
"password": "Password",
"token": "Token d'acc\u00e9s",
"model": "Model",
"debug": "Debug",
"noffline": "Ignore Offline message"
Expand All @@ -31,6 +32,7 @@
"data": {
"host": "Amfitri\u00f3",
"password": "Password",
"token": "Token d'acc\u00e9s",
"model": "Model",
"stats": "Stats",
"debug": "Debug",
Expand Down
2 changes: 2 additions & 0 deletions custom_components/aqara_gateway/translations/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"data": {
"host": "Hostitel",
"password": "Password",
"token": "P\u0159\u00edstupov\u00fd token",
"model": "Model",
"debug": "Debug",
"noffline": "Ignore Offline message"
Expand All @@ -31,6 +32,7 @@
"data": {
"host": "Hostitel",
"password": "Password",
"token": "P\u0159\u00edstupov\u00fd token",
"model": "Model",
"stats": "Stats",
"debug": "Debug",
Expand Down
2 changes: 2 additions & 0 deletions custom_components/aqara_gateway/translations/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"data": {
"host": "V\u00e6rt",
"password": "Password",
"token": "Token",
"model": "Model",
"debug": "Debug",
"noffline": "Ignore Offline message"
Expand All @@ -31,6 +32,7 @@
"data": {
"host": "V\u00e6rt",
"password": "Password",
"token": "Token",
"model": "Model",
"stats": "Stats",
"debug": "Debug",
Expand Down
2 changes: 2 additions & 0 deletions custom_components/aqara_gateway/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"data": {
"host": "Host",
"password": "Password",
"token": "Zugangstoken",
"model": "Model",
"debug": "Debug",
"noffline": "Ignore Offline message"
Expand All @@ -31,6 +32,7 @@
"data": {
"host": "Host",
"password": "Password",
"token": "Zugangstoken",
"model": "Model",
"stats": "Stats",
"debug": "Debug",
Expand Down
4 changes: 3 additions & 1 deletion custom_components/aqara_gateway/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
"data": {
"host": "Host",
"password": "Password",
"token": "Access Token",
"model": "Model",
"debug": "Debug",
"noffline": "Ignore Offline message"
},
"description": "Please enter connection settings of your Aqara Gateway."
"description": "Please enter connection settings of your Aqara Gateway. If you are first time to use gateway or telnet is not eanbled, the telnet of gateway need to be enabled. To enable telnet, please configure the gateway (for M1S, P3, H1) to Mijia home mode and obtain the token. For the method of obtaining the token, please refer to [this website](https://github.com/piotrmachowski/xiaomi-cloud-tokens-extractor). If telnet is enabled, there is no need to enter the token."
}
}
},
Expand All @@ -31,6 +32,7 @@
"data": {
"host": "Host",
"password": "Password",
"token": "Access Token",
"model": "Model",
"stats": "Stats",
"debug": "Debug",
Expand Down
2 changes: 2 additions & 0 deletions custom_components/aqara_gateway/translations/es-419.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"data": {
"host": "Host",
"password": "Password",
"token": "Token de acceso",
"model": "Model",
"debug": "Debug",
"noffline": "Ignore Offline message"
Expand All @@ -31,6 +32,7 @@
"data": {
"host": "Host",
"password": "Password",
"token": "Token de acceso",
"model": "Model",
"stats": "Stats",
"debug": "Debug",
Expand Down
2 changes: 2 additions & 0 deletions custom_components/aqara_gateway/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"data": {
"host": "Host",
"password": "Password",
"token": "Token de acceso",
"model": "Model",
"debug": "Debug",
"noffline": "Ignore Offline message"
Expand All @@ -31,6 +32,7 @@
"data": {
"host": "Host",
"password": "Password",
"token": "Token de acceso",
"model": "Model",
"stats": "Stats",
"debug": "Debug",
Expand Down
2 changes: 2 additions & 0 deletions custom_components/aqara_gateway/translations/et.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"data": {
"host": "Host",
"password": "Password",
"token": "Juurdep\u00e4\u00e4sut\u00f5end",
"model": "Model",
"debug": "Debug",
"noffline": "Ignore Offline message"
Expand All @@ -30,6 +31,7 @@
"data": {
"host": "Host",
"password": "Password",
"token": "Juurdep\u00e4\u00e4sut\u00f5end",
"model": "Model",
"stats": "Stats",
"debug": "Debug",
Expand Down
2 changes: 2 additions & 0 deletions custom_components/aqara_gateway/translations/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"data": {
"host": "Palvelin",
"password": "Password",
"token": "API-tunnus",
"model": "Model",
"debug": "Debug",
"noffline": "Ignore Offline message"
Expand All @@ -24,6 +25,7 @@
"data": {
"host": "Palvelin",
"password": "Password",
"token": "API-tunnus",
"model": "Model",
"stats": "Stats",
"debug": "Debug",
Expand Down
2 changes: 2 additions & 0 deletions custom_components/aqara_gateway/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"data": {
"host": "Nom d'h\u00f4te ou adresse IP",
"password": "Password",
"token": "jeton d'acc\u00e8s",
"model": "Model",
"debug": "Debug",
"noffline": "Ignore Offline message"
Expand All @@ -31,6 +32,7 @@
"data": {
"host": "Nom d'h\u00f4te ou adresse IP",
"password": "Password",
"token": "jeton d'acc\u00e8s",
"model": "Model",
"stats": "Stats",
"debug": "Debug",
Expand Down
2 changes: 2 additions & 0 deletions custom_components/aqara_gateway/translations/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"data": {
"host": "Hoszt",
"password": "Password",
"token": "Hozz\u00e1f\u00e9r\u00e9si token",
"model": "Model",
"debug": "Debug",
"noffline": "Ignore Offline message"
Expand All @@ -31,6 +32,7 @@
"data": {
"host": "Hoszt",
"password": "Password",
"token": "Hozz\u00e1f\u00e9r\u00e9si token",
"model": "Model",
"stats": "Stats",
"debug": "Debug",
Expand Down
2 changes: 2 additions & 0 deletions custom_components/aqara_gateway/translations/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"data": {
"host": "Host",
"password": "Kata kunci",
"token": "Token Akses",
"model": "Model",
"debug": "Debug",
"noffline": "Ignore Offline message"
Expand All @@ -31,6 +32,7 @@
"data": {
"host": "Host",
"password": "Kata kunci",
"token": "Token Akses",
"model": "Model",
"stats": "Stats",
"debug": "Debug",
Expand Down
2 changes: 2 additions & 0 deletions custom_components/aqara_gateway/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"data": {
"host": "Host",
"password": "Password",
"token": "Token di accesso",
"model": "Model",
"debug": "Debug",
"noffline": "Ignore Offline message"
Expand All @@ -31,6 +32,7 @@
"data": {
"host": "Host",
"password": "Password",
"token": "Token di accesso",
"model": "Model",
"stats": "Stats",
"debug": "Debug",
Expand Down
Loading

0 comments on commit 2b6e792

Please sign in to comment.