Compare commits

...

4 Commits

Author SHA1 Message Date
Andrey
6503d6bddd fix 1wire 2021-02-18 15:02:21 +03:00
Andrey
4af40c29a7 fix d 2021-02-18 14:10:04 +03:00
Andrey
75a41c9667 fix i2c 2021-02-18 12:36:43 +03:00
Andrey
4f8f38fde6 fix http response and ds2413 bugs 2021-02-18 12:07:55 +03:00
7 changed files with 30 additions and 9 deletions

View File

@@ -17,7 +17,7 @@ from homeassistant.components import mqtt
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from .const import DOMAIN, CONF_INVERT, CONF_RELOAD, PLATFORMS, CONF_PORTS, CONF_CUSTOM, CONF_SKIP, CONF_PORT_TO_SCAN, \ from .const import DOMAIN, CONF_INVERT, CONF_RELOAD, PLATFORMS, CONF_PORTS, CONF_CUSTOM, CONF_SKIP, CONF_PORT_TO_SCAN, \
CONF_MQTT_INPUTS, CONF_HTTP, CONF_RESPONSE_TEMPLATE, CONF_ACTION, CONF_GET_VALUE, CONF_ALLOW_HOSTS, \ CONF_MQTT_INPUTS, CONF_HTTP, CONF_RESPONSE_TEMPLATE, CONF_ACTION, CONF_GET_VALUE, CONF_ALLOW_HOSTS, \
CONF_CONV_TEMPLATE, CONF_ALL, CONF_FORCE_D CONF_CONV_TEMPLATE, CONF_ALL, CONF_FORCE_D, CONF_DEF_RESPONSE
from .hub import MegaD from .hub import MegaD
from .config_flow import ConfigFlow from .config_flow import ConfigFlow
from .http import MegaView from .http import MegaView
@@ -53,6 +53,11 @@ CONFIG_SCHEMA = vol.Schema(
vol.Optional(CONF_ALLOW_HOSTS): [str], vol.Optional(CONF_ALLOW_HOSTS): [str],
vol.Required(str, description='id меги из веб-интерфейса'): { vol.Required(str, description='id меги из веб-интерфейса'): {
vol.Optional(CONF_FORCE_D, description='Принудительно слать d после срабатывания входа', default=False): bool, vol.Optional(CONF_FORCE_D, description='Принудительно слать d после срабатывания входа', default=False): bool,
vol.Optional(
CONF_DEF_RESPONSE,
description='Ответ по умолчанию',
default=''
): cv.template,
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 = 6 VERSION = 8
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

@@ -28,6 +28,7 @@ CONF_ALLOW_HOSTS = 'allow_hosts'
CONF_CONV_TEMPLATE = 'conv_template' CONF_CONV_TEMPLATE = 'conv_template'
CONF_POLL_OUTS = 'poll_outs' CONF_POLL_OUTS = 'poll_outs'
CONF_FORCE_D = 'force_d' CONF_FORCE_D = 'force_d'
CONF_DEF_RESPONSE = 'def_response'
PLATFORMS = [ PLATFORMS = [
"light", "light",
"switch", "switch",

View File

@@ -253,7 +253,7 @@ class MegaOutPort(MegaPushEntity):
return self._state == 'ON' return self._state == 'ON'
elif val is not None: elif val is not None:
val = val.get("value") val = val.get("value")
if self.index is not None and self.addr is not None: if not isinstance(val, str) and self.index is not None and self.addr is not None:
if not isinstance(val, dict): if not isinstance(val, dict):
self.mega.lg.warning(f'{self.entity_id}: {val} is not a dict') self.mega.lg.warning(f'{self.entity_id}: {val} is not a dict')
return return

View File

@@ -66,12 +66,12 @@ class MegaView(HomeAssistantView):
update_all = False update_all = False
data['value'] = data.pop('v') data['value'] = data.pop('v')
data['mega_id'] = hub.id data['mega_id'] = hub.id
ret = 'd' ret = 'd' if hub.force_d else ''
if port is not None: if port is not None:
hub.values[port] = data hub.values[port] = data
for cb in self.callbacks[hub.id][port]: for cb in self.callbacks[hub.id][port]:
cb(data) cb(data)
template: Template = self.templates.get(hub.id, {}).get(port) template: Template = self.templates.get(hub.id, {}).get(port, hub.def_response)
if hub.update_all and update_all: if hub.update_all and update_all:
asyncio.create_task(self.later_update(hub)) asyncio.create_task(self.later_update(hub))
if template is not None: if template is not None:
@@ -79,11 +79,14 @@ class MegaView(HomeAssistantView):
ret = template.async_render(data) ret = template.async_render(data)
_LOGGER.debug('response %s', ret) _LOGGER.debug('response %s', ret)
Response(body='', content_type='text/plain', headers={'Server': 's', 'Date': 'n'}) Response(body='', content_type='text/plain', headers={'Server': 's', 'Date': 'n'})
await hub.request(cmd=ret) if 'd' in ret:
await hub.request(pt=port, cmd=ret)
else:
await hub.request(cmd=ret)
return ret return ret
async def later_update(self, hub): async def later_update(self, hub):
_LOGGER.debug('force update')
await asyncio.sleep(1) await asyncio.sleep(1)
_LOGGER.debug('force update')
await hub.updater.async_refresh() await hub.updater.async_refresh()

View File

@@ -19,7 +19,7 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from .const import ( from .const import (
TEMP, HUM, PRESS, TEMP, HUM, PRESS,
LUX, PATT_SPLIT, DOMAIN, LUX, PATT_SPLIT, DOMAIN,
CONF_HTTP, EVENT_BINARY_SENSOR, CONF_CUSTOM, CONF_FORCE_D CONF_HTTP, EVENT_BINARY_SENSOR, CONF_CUSTOM, CONF_FORCE_D, CONF_DEF_RESPONSE
) )
from .entities import set_events_off, BaseMegaEntity from .entities import set_events_off, BaseMegaEntity
from .exceptions import CannotConnect, NoPort from .exceptions import CannotConnect, NoPort
@@ -171,6 +171,10 @@ class MegaD:
def force_d(self): def force_d(self):
return self.customize.get(CONF_FORCE_D, False) return self.customize.get(CONF_FORCE_D, False)
@property
def def_response(self):
return self.customize.get(CONF_DEF_RESPONSE, None)
@property @property
def is_online(self): def is_online(self):
return (datetime.now() - self.last_update).total_seconds() < (self.poll_interval + 10) return (datetime.now() - self.last_update).total_seconds() < (self.poll_interval + 10)
@@ -260,7 +264,12 @@ class MegaD:
if 'busy' in ret: if 'busy' in ret:
return None return None
if ':' in ret: if ':' in ret:
ret = ret.split(';') if ';' in ret:
ret = ret.split(';')
elif '/' in ret:
ret = ret.split('/')
else:
ret = [ret]
ret = {'value': dict([ ret = {'value': dict([
x.split(':') for x in ret if x.count(':') == 1 x.split(':') for x in ret if x.count(':') == 1
])} ])}

View File

@@ -12,6 +12,9 @@
Обновление прошивки MegaD можно делать прямо из HA с помощью [аддона](https://github.com/andvikt/mega_addon.git) Обновление прошивки MegaD можно делать прямо из HA с помощью [аддона](https://github.com/andvikt/mega_addon.git)
Подробная документация по [ссылке](https://github.com/andvikt/mega_hacs/wiki) Подробная документация по [ссылке](https://github.com/andvikt/mega_hacs/wiki)
Предложения по доработкам просьба писать в [discussions](https://github.com/andvikt/mega_hacs/discussions), о проблемах
создавать [issue](https://github.com/andvikt/mega_hacs/issues/new/choose)
## Основные особенности: ## Основные особенности:
- Настройка в веб-интерфейсе + yaml - Настройка в веб-интерфейсе + yaml
- Все порты автоматически добавляются как устройства (для обычных релейных выходов создается - Все порты автоматически добавляются как устройства (для обычных релейных выходов создается