mirror of
https://github.com/home-assistant/core.git
synced 2025-04-27 02:37:50 +00:00
Improve logging elgato (#47681)
This commit is contained in:
parent
fd1add8f15
commit
ed679b263b
@ -1,4 +1,6 @@
|
|||||||
"""Support for Elgato Key Lights."""
|
"""Support for Elgato Key Lights."""
|
||||||
|
import logging
|
||||||
|
|
||||||
from elgato import Elgato, ElgatoConnectionError
|
from elgato import Elgato, ElgatoConnectionError
|
||||||
|
|
||||||
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
|
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
|
||||||
@ -30,6 +32,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
try:
|
try:
|
||||||
await elgato.info()
|
await elgato.info()
|
||||||
except ElgatoConnectionError as exception:
|
except ElgatoConnectionError as exception:
|
||||||
|
logging.getLogger(__name__).debug("Unable to connect: %s", exception)
|
||||||
raise ConfigEntryNotReady from exception
|
raise ConfigEntryNotReady from exception
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
|
@ -55,25 +55,20 @@ class ElgatoLight(LightEntity):
|
|||||||
info: Info,
|
info: Info,
|
||||||
):
|
):
|
||||||
"""Initialize Elgato Key Light."""
|
"""Initialize Elgato Key Light."""
|
||||||
self._brightness: int | None = None
|
|
||||||
self._info: Info = info
|
self._info: Info = info
|
||||||
self._state: bool | None = None
|
self._state: State | None = None
|
||||||
self._temperature: int | None = None
|
|
||||||
self._available = True
|
|
||||||
self.elgato = elgato
|
self.elgato = elgato
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Return the name of the entity."""
|
"""Return the name of the entity."""
|
||||||
# Return the product name, if display name is not set
|
# Return the product name, if display name is not set
|
||||||
if not self._info.display_name:
|
return self._info.display_name or self._info.product_name
|
||||||
return self._info.product_name
|
|
||||||
return self._info.display_name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
"""Return True if entity is available."""
|
"""Return True if entity is available."""
|
||||||
return self._available
|
return self._state is not None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self) -> str:
|
def unique_id(self) -> str:
|
||||||
@ -83,12 +78,14 @@ class ElgatoLight(LightEntity):
|
|||||||
@property
|
@property
|
||||||
def brightness(self) -> int | None:
|
def brightness(self) -> int | None:
|
||||||
"""Return the brightness of this light between 1..255."""
|
"""Return the brightness of this light between 1..255."""
|
||||||
return self._brightness
|
assert self._state is not None
|
||||||
|
return round((self._state.brightness * 255) / 100)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def color_temp(self) -> int | None:
|
def color_temp(self) -> int | None:
|
||||||
"""Return the CT color value in mireds."""
|
"""Return the CT color value in mireds."""
|
||||||
return self._temperature
|
assert self._state is not None
|
||||||
|
return self._state.temperature
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def min_mireds(self) -> int:
|
def min_mireds(self) -> int:
|
||||||
@ -108,7 +105,8 @@ class ElgatoLight(LightEntity):
|
|||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return the state of the light."""
|
"""Return the state of the light."""
|
||||||
return bool(self._state)
|
assert self._state is not None
|
||||||
|
return self._state.on
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Turn off the light."""
|
"""Turn off the light."""
|
||||||
@ -131,22 +129,19 @@ class ElgatoLight(LightEntity):
|
|||||||
await self.elgato.light(**data)
|
await self.elgato.light(**data)
|
||||||
except ElgatoError:
|
except ElgatoError:
|
||||||
_LOGGER.error("An error occurred while updating the Elgato Key Light")
|
_LOGGER.error("An error occurred while updating the Elgato Key Light")
|
||||||
self._available = False
|
self._state = None
|
||||||
|
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
"""Update Elgato entity."""
|
"""Update Elgato entity."""
|
||||||
|
restoring = self._state is None
|
||||||
try:
|
try:
|
||||||
state: State = await self.elgato.state()
|
self._state: State = await self.elgato.state()
|
||||||
except ElgatoError:
|
if restoring:
|
||||||
if self._available:
|
_LOGGER.info("Connection restored")
|
||||||
_LOGGER.error("An error occurred while updating the Elgato Key Light")
|
except ElgatoError as err:
|
||||||
self._available = False
|
meth = _LOGGER.error if self._state else _LOGGER.debug
|
||||||
return
|
meth("An error occurred while updating the Elgato Key Light: %s", err)
|
||||||
|
self._state = None
|
||||||
self._available = True
|
|
||||||
self._brightness = round((state.brightness * 255) / 100)
|
|
||||||
self._state = state.on
|
|
||||||
self._temperature = state.temperature
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self) -> dict[str, Any]:
|
def device_info(self) -> dict[str, Any]:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user