mirror of
https://github.com/andvikt/mega_hacs.git
synced 2025-12-12 01:24:29 +05:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
adb65529a2 | ||
|
|
768d46d952 | ||
|
|
359c6b99b7 | ||
|
|
79dc46226a |
@@ -1,5 +1,6 @@
|
|||||||
"""Platform for light integration."""
|
"""Platform for light integration."""
|
||||||
import logging
|
import logging
|
||||||
|
import asyncio
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@@ -69,7 +70,8 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn
|
|||||||
|
|
||||||
async_add_devices(devices)
|
async_add_devices(devices)
|
||||||
|
|
||||||
await scan()
|
asyncio.create_task(scan())
|
||||||
|
|
||||||
|
|
||||||
class MegaBinarySensor(BinarySensorEntity, BaseMegaEntity):
|
class MegaBinarySensor(BinarySensorEntity, BaseMegaEntity):
|
||||||
|
|
||||||
|
|||||||
@@ -153,10 +153,12 @@ class MegaD:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
if '"value":NA' in msg.payload.decode():
|
if '"value":NA' in msg.payload.decode():
|
||||||
ftr.set_result(None)
|
if not ftr.done():
|
||||||
|
ftr.set_result(None)
|
||||||
return
|
return
|
||||||
ret = json.loads(msg.payload).get('value')
|
ret = json.loads(msg.payload).get('value')
|
||||||
ftr.set_result(ret)
|
if not ftr.done():
|
||||||
|
ftr.set_result(ret)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
ret = None
|
ret = None
|
||||||
self.lg.exception(f'while parsing response from port {port}: {msg.payload}')
|
self.lg.exception(f'while parsing response from port {port}: {msg.payload}')
|
||||||
@@ -167,12 +169,12 @@ class MegaD:
|
|||||||
)
|
)
|
||||||
|
|
||||||
async with self.lck:
|
async with self.lck:
|
||||||
|
unsub = await self.mqtt.async_subscribe(
|
||||||
|
topic=f'{self.mqtt_id}/{port}',
|
||||||
|
msg_callback=cb,
|
||||||
|
qos=1,
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
unsub = await self.mqtt.async_subscribe(
|
|
||||||
topic=f'{self.mqtt_id}/{port}',
|
|
||||||
msg_callback=cb,
|
|
||||||
qos=1,
|
|
||||||
)
|
|
||||||
await self.mqtt.async_publish(
|
await self.mqtt.async_publish(
|
||||||
topic=f'{self.mqtt_id}/cmd',
|
topic=f'{self.mqtt_id}/cmd',
|
||||||
payload=f'get:{port}',
|
payload=f'get:{port}',
|
||||||
@@ -268,8 +270,7 @@ class MegaD:
|
|||||||
return pty, m
|
return pty, m
|
||||||
|
|
||||||
async def scan_ports(self,):
|
async def scan_ports(self,):
|
||||||
async with self.lck:
|
for x in range(38):
|
||||||
for x in range(38):
|
ret = await self.scan_port(x)
|
||||||
ret = await self.scan_port(x)
|
if ret:
|
||||||
if ret:
|
yield [x, *ret]
|
||||||
yield [x, *ret]
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"""Platform for light integration."""
|
"""Platform for light integration."""
|
||||||
import logging
|
import logging
|
||||||
|
import asyncio
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
@@ -85,7 +85,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn
|
|||||||
devices.append(light)
|
devices.append(light)
|
||||||
async_add_devices(devices)
|
async_add_devices(devices)
|
||||||
|
|
||||||
await scan_ports()
|
asyncio.create_task(scan_ports())
|
||||||
|
|
||||||
|
|
||||||
class MegaLight(LightEntity, BaseMegaEntity):
|
class MegaLight(LightEntity, BaseMegaEntity):
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
"""Platform for light integration."""
|
"""Platform for light integration."""
|
||||||
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@@ -94,7 +95,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn
|
|||||||
if values is None:
|
if values is None:
|
||||||
continue
|
continue
|
||||||
if isinstance(values, str) and TEMP_PATT.search(values):
|
if isinstance(values, str) and TEMP_PATT.search(values):
|
||||||
values = {TEMP: values}
|
values = {TEMP: values}
|
||||||
elif not isinstance(values, dict):
|
elif not isinstance(values, dict):
|
||||||
values = {None: values}
|
values = {None: values}
|
||||||
for key in values:
|
for key in values:
|
||||||
@@ -111,7 +112,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn
|
|||||||
|
|
||||||
async_add_devices(devices)
|
async_add_devices(devices)
|
||||||
|
|
||||||
await scan()
|
asyncio.create_task(scan())
|
||||||
|
|
||||||
|
|
||||||
class Mega1WSensor(BaseMegaEntity):
|
class Mega1WSensor(BaseMegaEntity):
|
||||||
|
|||||||
Reference in New Issue
Block a user