Skip to content

Commit 321d923

Browse files
committed
Add custom open telnet command option
1 parent b18dd23 commit 321d923

4 files changed

Lines changed: 20 additions & 6 deletions

File tree

custom_components/xiaomi_gateway3/config_flow.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from . import DOMAIN
1010
from .core import gateway3
11+
from .core.gateway3 import TELNET_CMD
1112
from .core.xiaomi_cloud import MiCloud
1213

1314
_LOGGER = logging.getLogger(__name__)
@@ -56,8 +57,8 @@ async def async_step_user(self, user_input=None):
5657
data_schema=vol.Schema({
5758
vol.Required('host', default=device['localip']): str,
5859
vol.Required('token', default=device['token']): str,
60+
vol.Required('telnet_cmd', default=TELNET_CMD): str,
5961
}),
60-
description_placeholders={'error_text': ''}
6162
)
6263

6364
if DOMAIN in self.hass.data and 'devices' in self.hass.data[DOMAIN]:
@@ -116,6 +117,7 @@ async def async_step_token(self, user_input=None, error=None):
116117
data_schema=vol.Schema({
117118
vol.Required('host'): str,
118119
vol.Required('token'): str,
120+
vol.Required('telnet_cmd', default=TELNET_CMD): str,
119121
}),
120122
errors={'base': error} if error else None
121123
)
@@ -180,6 +182,7 @@ async def async_step_user(self, user_input=None):
180182

181183
host = self.entry.options['host']
182184
token = self.entry.options['token']
185+
telnet_cmd = self.entry.options.get('telnet_cmd')
183186
ble = self.entry.options.get('ble', True)
184187
stats = self.entry.options.get('stats', False)
185188
debug = self.entry.options.get('debug', [])
@@ -192,6 +195,7 @@ async def async_step_user(self, user_input=None):
192195
data_schema=vol.Schema({
193196
vol.Required('host', default=host): str,
194197
vol.Required('token', default=token): str,
198+
vol.Optional('telnet_cmd', default=telnet_cmd): str,
195199
vol.Required('ble', default=ble): bool,
196200
vol.Required('stats', default=stats): bool,
197201
vol.Optional('debug', default=debug): cv.multi_select(

custom_components/xiaomi_gateway3/core/gateway3.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
# MAC reverse
2323
RE_REVERSE = re.compile(r'(..)(..)(..)(..)(..)(..)')
2424

25+
TELNET_CMD = '{"method":"enable_telnet_service","params":""}'
26+
2527

2628
class GatewayV:
2729
"""Handling different firmware versions."""
@@ -339,6 +341,7 @@ class Gateway3(Thread, GatewayV, GatewayMesh, GatewayStats):
339341
time_offset = 0
340342
pair_model = None
341343
pair_payload = None
344+
telnet_cmd = None
342345

343346
def __init__(self, host: str, token: str, config: dict, **options):
344347
super().__init__(daemon=True)
@@ -359,6 +362,8 @@ def __init__(self, host: str, token: str, config: dict, **options):
359362
else options['parent'])
360363
self.default_devices = config['devices'] if config else None
361364

365+
self.telnet_cmd = options.get('telnet_cmd') or TELNET_CMD
366+
362367
if 'true' in self._debug:
363368
self.miio.debug = True
364369

@@ -444,7 +449,8 @@ def _check_port(self, port: int):
444449

445450
def _enable_telnet(self):
446451
"""Enable telnet with miio protocol."""
447-
if self.miio.send("enable_telnet_service") != 'ok':
452+
raw = json.loads(self.telnet_cmd)
453+
if self.miio.send(raw['method'], raw.get('params')) != 'ok':
448454
self.debug(f"Can't enable telnet")
449455
return False
450456
return True

custom_components/xiaomi_gateway3/translations/en.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
}
2424
},
2525
"token": {
26-
"description": "[Obtain](https://github.com/Maxmudjon/com.xiaomi-miio/blob/master/docs/obtain_token.md) Mi Home token.\nNote: Gateway with firmware **1.4.6_0043** higher are supported only after [soldering](https://github.com/AlexxIT/XiaomiGateway3/wiki)",
26+
"description": "You can obtain Mi Home token automatically with [Cloud integration](https://github.com/AlexxIT/XiaomiGateway3#obtain-mi-home-device-token) or [manually](https://github.com/Maxmudjon/com.xiaomi-miio/blob/master/docs/obtain_token.md). Check supported firmwares info in [component docs](https://github.com/AlexxIT/XiaomiGateway3#supported-firmwares).",
2727
"data": {
2828
"host": "Host",
29-
"token": "Token"
29+
"token": "Token",
30+
"telnet_cmd": "Open Telnet command"
3031
}
3132
}
3233
}
@@ -45,6 +46,7 @@
4546
"data": {
4647
"host": "Host",
4748
"token": "Token",
49+
"telnet_cmd": "Open Telnet command",
4850
"ble": "Support BLE Devices",
4951
"stats": "Zigbee and BLE performance data",
5052
"debug": "Debug",

custom_components/xiaomi_gateway3/translations/ru.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
}
2424
},
2525
"token": {
26-
"description": "[Получите](https://github.com/Maxmudjon/com.xiaomi-miio/blob/master/docs/obtain_token.md) Mi Home токен. Шлюз с прошивкой **1.4.6_0043** и выше поддерживается только после [перепрошивки](https://github.com/AlexxIT/XiaomiGateway3/wiki)",
26+
"description": "Вы можете получить Mi Home токен автоматически с помощью [облачной интеграции](https://github.com/AlexxIT/XiaomiGateway3#obtain-mi-home-device-token) или [вручную](https://github.com/Maxmudjon/com.xiaomi-miio/blob/master/docs/obtain_token.md). Ознакомьтесь с поддерживаемыми версиями прошивок в [документации компонента](https://github.com/AlexxIT/XiaomiGateway3#supported-firmwares).",
2727
"data": {
2828
"host": "IP-адрес",
29-
"token": "Токен"
29+
"token": "Токен",
30+
"telnet_cmd": "Команда для открытия Telnet"
3031
}
3132
}
3233
}
@@ -45,6 +46,7 @@
4546
"data": {
4647
"host": "IP-адрес",
4748
"token": "Токен",
49+
"telnet_cmd": "Команда для открытия Telnet",
4850
"ble": "Поддержка BLE устройств",
4951
"stats": "Детализация работы Zigbee и BLE",
5052
"debug": "Отладка",

0 commit comments

Comments
 (0)