mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add get method to DhcpServiceInfo (#60527)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
a88cc8b98c
commit
0f2e39adee
@ -46,6 +46,8 @@ from homeassistant.loader import async_get_dhcp
|
|||||||
from homeassistant.util.async_ import run_callback_threadsafe
|
from homeassistant.util.async_ import run_callback_threadsafe
|
||||||
from homeassistant.util.network import is_invalid, is_link_local, is_loopback
|
from homeassistant.util.network import is_invalid, is_link_local, is_loopback
|
||||||
|
|
||||||
|
from .const import DOMAIN
|
||||||
|
|
||||||
FILTER = "udp and (port 67 or 68)"
|
FILTER = "udp and (port 67 or 68)"
|
||||||
REQUESTED_ADDR = "requested_addr"
|
REQUESTED_ADDR = "requested_addr"
|
||||||
MESSAGE_TYPE = "message-type"
|
MESSAGE_TYPE = "message-type"
|
||||||
@ -71,20 +73,38 @@ class DhcpServiceInfo(BaseServiceInfo):
|
|||||||
|
|
||||||
def __getitem__(self, name: str) -> Any:
|
def __getitem__(self, name: str) -> Any:
|
||||||
"""
|
"""
|
||||||
Allow property access by name for compatibility reason.
|
Enable method for compatibility reason.
|
||||||
|
|
||||||
Deprecated, and will be removed in version 2022.6.
|
Deprecated, and will be removed in version 2022.6.
|
||||||
"""
|
"""
|
||||||
if not self._warning_logged:
|
if not self._warning_logged:
|
||||||
report(
|
report(
|
||||||
f"accessed discovery_info['{name}'] instead of discovery_info.{name}; this will fail in version 2022.6",
|
f"accessed discovery_info['{name}'] instead of discovery_info.{name}; this will fail in version 2022.6",
|
||||||
exclude_integrations={"dhcp"},
|
exclude_integrations={DOMAIN},
|
||||||
error_if_core=False,
|
error_if_core=False,
|
||||||
level=logging.DEBUG,
|
level=logging.DEBUG,
|
||||||
)
|
)
|
||||||
self._warning_logged = True
|
self._warning_logged = True
|
||||||
return getattr(self, name)
|
return getattr(self, name)
|
||||||
|
|
||||||
|
def get(self, name: str, default: Any = None) -> Any:
|
||||||
|
"""
|
||||||
|
Enable method for compatibility reason.
|
||||||
|
|
||||||
|
Deprecated, and will be removed in version 2022.6.
|
||||||
|
"""
|
||||||
|
if not self._warning_logged:
|
||||||
|
report(
|
||||||
|
f"accessed discovery_info.get('{name}') instead of discovery_info.{name}; this will fail in version 2022.6",
|
||||||
|
exclude_integrations={DOMAIN},
|
||||||
|
error_if_core=False,
|
||||||
|
level=logging.DEBUG,
|
||||||
|
)
|
||||||
|
self._warning_logged = True
|
||||||
|
if hasattr(self, name):
|
||||||
|
return getattr(self, name)
|
||||||
|
return default
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the dhcp component."""
|
"""Set up the dhcp component."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user