mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Add debug log and Optimize code (#134328)
* debug log * add sw_version hw_version * log
This commit is contained in:
parent
c9ff575628
commit
87454babfa
@ -9,7 +9,7 @@ from refoss_ha.discovery import Discovery, Listener
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
|
||||
from .const import COORDINATORS, DISPATCH_DEVICE_DISCOVERED, DOMAIN
|
||||
from .const import _LOGGER, COORDINATORS, DISPATCH_DEVICE_DISCOVERED, DOMAIN
|
||||
from .coordinator import RefossDataUpdateCoordinator
|
||||
|
||||
|
||||
@ -36,11 +36,21 @@ class DiscoveryService(Listener):
|
||||
self.hass.data[DOMAIN][COORDINATORS].append(coordo)
|
||||
await coordo.async_refresh()
|
||||
|
||||
_LOGGER.debug(
|
||||
"Discover new device: %s, ip: %s",
|
||||
device_info.dev_name,
|
||||
device_info.inner_ip,
|
||||
)
|
||||
async_dispatcher_send(self.hass, DISPATCH_DEVICE_DISCOVERED, coordo)
|
||||
|
||||
async def device_update(self, device_info: DeviceInfo) -> None:
|
||||
"""Handle updates in device information, update if ip has changed."""
|
||||
for coordinator in self.hass.data[DOMAIN][COORDINATORS]:
|
||||
if coordinator.device.device_info.mac == device_info.mac:
|
||||
_LOGGER.debug(
|
||||
"Update device %s ip to %s",
|
||||
device_info.dev_name,
|
||||
device_info.inner_ip,
|
||||
)
|
||||
coordinator.device.device_info.inner_ip = device_info.inner_ip
|
||||
await coordinator.async_refresh()
|
||||
|
@ -5,7 +5,7 @@ from __future__ import annotations
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_entry_flow
|
||||
|
||||
from .const import DISCOVERY_TIMEOUT, DOMAIN
|
||||
from .const import _LOGGER, DISCOVERY_TIMEOUT, DOMAIN
|
||||
from .util import refoss_discovery_server
|
||||
|
||||
|
||||
@ -14,6 +14,9 @@ async def _async_has_devices(hass: HomeAssistant) -> bool:
|
||||
|
||||
refoss_discovery = await refoss_discovery_server(hass)
|
||||
devices = await refoss_discovery.broadcast_msg(wait_for=DISCOVERY_TIMEOUT)
|
||||
_LOGGER.debug(
|
||||
"Discovered devices: [%s]", ", ".join([info.dev_name for info in devices])
|
||||
)
|
||||
return len(devices) > 0
|
||||
|
||||
|
||||
|
@ -11,7 +11,7 @@ COORDINATORS = "coordinators"
|
||||
DATA_DISCOVERY_SERVICE = "refoss_discovery"
|
||||
|
||||
DISCOVERY_SCAN_INTERVAL = 30
|
||||
DISCOVERY_TIMEOUT = 8
|
||||
DISCOVERY_TIMEOUT = 20
|
||||
DISPATCH_DEVICE_DISCOVERED = "refoss_device_discovered"
|
||||
DISPATCHERS = "dispatchers"
|
||||
|
||||
|
@ -34,6 +34,11 @@ class RefossDataUpdateCoordinator(DataUpdateCoordinator[None]):
|
||||
self.last_update_success = True
|
||||
self._error_count = 0
|
||||
except DeviceTimeoutError:
|
||||
_LOGGER.debug(
|
||||
"Update device %s status timeout,ip: %s",
|
||||
self.device.dev_name,
|
||||
self.device.inner_ip,
|
||||
)
|
||||
self._error_count += 1
|
||||
|
||||
if self._error_count >= MAX_ERRORS:
|
||||
|
@ -23,5 +23,7 @@ class RefossEntity(CoordinatorEntity[RefossDataUpdateCoordinator]):
|
||||
connections={(CONNECTION_NETWORK_MAC, mac)},
|
||||
identifiers={(DOMAIN, mac)},
|
||||
manufacturer="Refoss",
|
||||
sw_version=coordinator.device.fmware_version,
|
||||
hw_version=coordinator.device.hdware_version,
|
||||
name=coordinator.device.dev_name,
|
||||
)
|
||||
|
@ -5,5 +5,6 @@
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/refoss",
|
||||
"iot_class": "local_polling",
|
||||
"requirements": ["refoss-ha==1.2.5"]
|
||||
"requirements": ["refoss-ha==1.2.5"],
|
||||
"single_config_entry": true
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ from homeassistant.helpers.typing import StateType
|
||||
|
||||
from .bridge import RefossDataUpdateCoordinator
|
||||
from .const import (
|
||||
_LOGGER,
|
||||
CHANNEL_DISPLAY_NAME,
|
||||
COORDINATORS,
|
||||
DISPATCH_DEVICE_DISCOVERED,
|
||||
@ -143,6 +144,7 @@ async def async_setup_entry(
|
||||
for channel in device.channels
|
||||
for description in descriptions
|
||||
)
|
||||
_LOGGER.debug("Device %s add sensor entity success", device.dev_name)
|
||||
|
||||
for coordinator in hass.data[DOMAIN][COORDINATORS]:
|
||||
init_device(coordinator)
|
||||
|
@ -13,7 +13,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .bridge import RefossDataUpdateCoordinator
|
||||
from .const import COORDINATORS, DISPATCH_DEVICE_DISCOVERED, DOMAIN
|
||||
from .const import _LOGGER, COORDINATORS, DISPATCH_DEVICE_DISCOVERED, DOMAIN
|
||||
from .entity import RefossEntity
|
||||
|
||||
|
||||
@ -37,6 +37,7 @@ async def async_setup_entry(
|
||||
new_entities.append(entity)
|
||||
|
||||
async_add_entities(new_entities)
|
||||
_LOGGER.debug("Device %s add switch entity success", device.dev_name)
|
||||
|
||||
for coordinator in hass.data[DOMAIN][COORDINATORS]:
|
||||
init_device(coordinator)
|
||||
|
@ -5149,7 +5149,8 @@
|
||||
"name": "Refoss",
|
||||
"integration_type": "hub",
|
||||
"config_flow": true,
|
||||
"iot_class": "local_polling"
|
||||
"iot_class": "local_polling",
|
||||
"single_config_entry": true
|
||||
},
|
||||
"rejseplanen": {
|
||||
"name": "Rejseplanen",
|
||||
|
Loading…
x
Reference in New Issue
Block a user