mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 01:07:10 +00:00
Add yaml key to Shelly to allow CoAP port customization (#48729)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
552ca1c57b
commit
cf96d86985
@ -5,6 +5,7 @@ import logging
|
|||||||
|
|
||||||
import aioshelly
|
import aioshelly
|
||||||
import async_timeout
|
import async_timeout
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -17,6 +18,7 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers import aiohttp_client, device_registry, update_coordinator
|
from homeassistant.helpers import aiohttp_client, device_registry, update_coordinator
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
AIOSHELLY_DEVICE_TIMEOUT_SEC,
|
AIOSHELLY_DEVICE_TIMEOUT_SEC,
|
||||||
@ -25,7 +27,9 @@ from .const import (
|
|||||||
ATTR_DEVICE,
|
ATTR_DEVICE,
|
||||||
BATTERY_DEVICES_WITH_PERMANENT_CONNECTION,
|
BATTERY_DEVICES_WITH_PERMANENT_CONNECTION,
|
||||||
COAP,
|
COAP,
|
||||||
|
CONF_COAP_PORT,
|
||||||
DATA_CONFIG_ENTRY,
|
DATA_CONFIG_ENTRY,
|
||||||
|
DEFAULT_COAP_PORT,
|
||||||
DEVICE,
|
DEVICE,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
EVENT_SHELLY_CLICK,
|
EVENT_SHELLY_CLICK,
|
||||||
@ -43,10 +47,22 @@ PLATFORMS = ["binary_sensor", "cover", "light", "sensor", "switch"]
|
|||||||
SLEEPING_PLATFORMS = ["binary_sensor", "sensor"]
|
SLEEPING_PLATFORMS = ["binary_sensor", "sensor"]
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
COAP_SCHEMA = vol.Schema(
|
||||||
|
{
|
||||||
|
vol.Optional(CONF_COAP_PORT, default=DEFAULT_COAP_PORT): cv.port,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
CONFIG_SCHEMA = vol.Schema({DOMAIN: COAP_SCHEMA}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: dict):
|
async def async_setup(hass: HomeAssistant, config: dict):
|
||||||
"""Set up the Shelly component."""
|
"""Set up the Shelly component."""
|
||||||
hass.data[DOMAIN] = {DATA_CONFIG_ENTRY: {}}
|
hass.data[DOMAIN] = {DATA_CONFIG_ENTRY: {}}
|
||||||
|
|
||||||
|
conf = config.get(DOMAIN)
|
||||||
|
if conf is not None:
|
||||||
|
hass.data[DOMAIN][CONF_COAP_PORT] = conf[CONF_COAP_PORT]
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,6 +6,9 @@ DEVICE = "device"
|
|||||||
DOMAIN = "shelly"
|
DOMAIN = "shelly"
|
||||||
REST = "rest"
|
REST = "rest"
|
||||||
|
|
||||||
|
CONF_COAP_PORT = "coap_port"
|
||||||
|
DEFAULT_COAP_PORT = 5683
|
||||||
|
|
||||||
# Used in "_async_update_data" as timeout for polling data from devices.
|
# Used in "_async_update_data" as timeout for polling data from devices.
|
||||||
POLLING_TIMEOUT_SEC = 18
|
POLLING_TIMEOUT_SEC = 18
|
||||||
|
|
||||||
|
@ -14,7 +14,9 @@ from homeassistant.util.dt import parse_datetime, utcnow
|
|||||||
from .const import (
|
from .const import (
|
||||||
BASIC_INPUTS_EVENTS_TYPES,
|
BASIC_INPUTS_EVENTS_TYPES,
|
||||||
COAP,
|
COAP,
|
||||||
|
CONF_COAP_PORT,
|
||||||
DATA_CONFIG_ENTRY,
|
DATA_CONFIG_ENTRY,
|
||||||
|
DEFAULT_COAP_PORT,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SHBTN_INPUTS_EVENTS_TYPES,
|
SHBTN_INPUTS_EVENTS_TYPES,
|
||||||
SHBTN_MODELS,
|
SHBTN_MODELS,
|
||||||
@ -190,7 +192,13 @@ def get_device_wrapper(hass: HomeAssistant, device_id: str):
|
|||||||
async def get_coap_context(hass):
|
async def get_coap_context(hass):
|
||||||
"""Get CoAP context to be used in all Shelly devices."""
|
"""Get CoAP context to be used in all Shelly devices."""
|
||||||
context = aioshelly.COAP()
|
context = aioshelly.COAP()
|
||||||
await context.initialize()
|
port = DEFAULT_COAP_PORT
|
||||||
|
if DOMAIN in hass.data:
|
||||||
|
port = hass.data[DOMAIN].get(CONF_COAP_PORT, DEFAULT_COAP_PORT)
|
||||||
|
else:
|
||||||
|
port = DEFAULT_COAP_PORT
|
||||||
|
_LOGGER.info("Starting CoAP context with UDP port %s", port)
|
||||||
|
await context.initialize(port)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def shutdown_listener(ev):
|
def shutdown_listener(ev):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user