Compare commits

..

5 Commits

Author SHA1 Message Date
Andrey
80e43888b9 fix force_d 2021-02-18 15:45:13 +03:00
Andrey
ba41cbb100 fix 1wire bus 2021-02-18 15:41:12 +03:00
Andrey
0b5b9744ba fix 1wire bus 2021-02-18 15:40:59 +03:00
Andrey
9746311f38 fix 1wire bus 2021-02-18 15:40:31 +03:00
Andrey
38a525f2f5 fix 2021-02-18 15:16:43 +03:00
3 changed files with 13 additions and 8 deletions

View File

@@ -56,8 +56,8 @@ CONFIG_SCHEMA = vol.Schema(
vol.Optional( vol.Optional(
CONF_DEF_RESPONSE, CONF_DEF_RESPONSE,
description='Ответ по умолчанию', description='Ответ по умолчанию',
default='' default=None
): cv.template, ): vol.Any(cv.template, None),
vol.Optional(int, description='номер порта'): vol.Any( vol.Optional(int, description='номер порта'): vol.Any(
CUSTOMIZE_PORT, CUSTOMIZE_PORT,
CUSTOMIZE_DS2413, CUSTOMIZE_DS2413,

View File

@@ -57,7 +57,7 @@ async def validate_input(hass: core.HomeAssistant, data):
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for mega.""" """Handle a config flow for mega."""
VERSION = 8 VERSION = 10
CONNECTION_CLASS = config_entries.CONN_CLASS_ASSUMED CONNECTION_CLASS = config_entries.CONN_CLASS_ASSUMED
async def async_step_user(self, user_input=None): async def async_step_user(self, user_input=None):

View File

@@ -258,7 +258,7 @@ class MegaD:
async def save(self): async def save(self):
await self.send_command(cmd='s') await self.send_command(cmd='s')
def parse_response(self, ret): def parse_response(self, ret, cmd='get'):
if ret is None: if ret is None:
raise NoPort() raise NoPort()
if 'busy' in ret: if 'busy' in ret:
@@ -266,7 +266,7 @@ class MegaD:
if ':' in ret: if ':' in ret:
if ';' in ret: if ';' in ret:
ret = ret.split(';') ret = ret.split(';')
elif '/' in ret: elif '/' in ret and not cmd == 'list':
ret = ret.split('/') ret = ret.split('/')
else: else:
ret = [ret] ret = [ret]
@@ -291,7 +291,7 @@ class MegaD:
if http_cmd == 'list' and conv: if http_cmd == 'list' and conv:
await self.request(pt=port, cmd='conv') await self.request(pt=port, cmd='conv')
await asyncio.sleep(1) await asyncio.sleep(1)
ret = self.parse_response(await self.request(pt=port, cmd=http_cmd)) ret = self.parse_response(await self.request(pt=port, cmd=http_cmd), cmd=http_cmd)
ntry = 0 ntry = 0
while http_cmd == 'list' and ret is None and ntry < 3: while http_cmd == 'list' and ret is None and ntry < 3:
await asyncio.sleep(1) await asyncio.sleep(1)
@@ -480,10 +480,15 @@ class MegaD:
elif pty in ('3', '2', '4'): elif pty in ('3', '2', '4'):
try: try:
http_cmd = 'get' http_cmd = 'get'
values = await self.get_port(port, force_http=True) if m == '5' and pty == '3':
if values is None or (isinstance(values, dict) and str(values.get('value')) in ('', 'None')): # 1-wire bus
values = await self.get_port(port, force_http=True, http_cmd='list') values = await self.get_port(port, force_http=True, http_cmd='list')
http_cmd = 'list' http_cmd = 'list'
else:
values = await self.get_port(port, force_http=True)
if values is None or (isinstance(values, dict) and str(values.get('value')) in ('', 'None')):
values = await self.get_port(port, force_http=True, http_cmd='list')
http_cmd = 'list'
except asyncio.TimeoutError: except asyncio.TimeoutError:
self.lg.warning(f'timout on port {port}') self.lg.warning(f'timout on port {port}')
continue continue