mirror of
https://github.com/home-assistant/core
synced 2024-09-03 08:14:07 +02:00
Separate words with underscore in onewire (#72758)
This commit is contained in:
parent
3ea304aaf1
commit
cf27b82d2f
@ -18,16 +18,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a 1-Wire proxy for a config entry."""
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
|
||||
onewirehub = OneWireHub(hass)
|
||||
onewire_hub = OneWireHub(hass)
|
||||
try:
|
||||
await onewirehub.initialize(entry)
|
||||
await onewire_hub.initialize(entry)
|
||||
except (
|
||||
CannotConnect, # Failed to connect to the server
|
||||
protocol.OwnetError, # Connected to server, but failed to list the devices
|
||||
) as exc:
|
||||
raise ConfigEntryNotReady() from exc
|
||||
|
||||
hass.data[DOMAIN][entry.entry_id] = onewirehub
|
||||
hass.data[DOMAIN][entry.entry_id] = onewire_hub
|
||||
|
||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||
|
||||
@ -40,9 +40,9 @@ async def async_remove_config_entry_device(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry, device_entry: dr.DeviceEntry
|
||||
) -> bool:
|
||||
"""Remove a config entry from a device."""
|
||||
onewirehub: OneWireHub = hass.data[DOMAIN][config_entry.entry_id]
|
||||
onewire_hub: OneWireHub = hass.data[DOMAIN][config_entry.entry_id]
|
||||
return not device_entry.identifiers.intersection(
|
||||
(DOMAIN, device.id) for device in onewirehub.devices or []
|
||||
(DOMAIN, device.id) for device in onewire_hub.devices or []
|
||||
)
|
||||
|
||||
|
||||
|
@ -94,19 +94,19 @@ async def async_setup_entry(
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up 1-Wire platform."""
|
||||
onewirehub = hass.data[DOMAIN][config_entry.entry_id]
|
||||
onewire_hub = hass.data[DOMAIN][config_entry.entry_id]
|
||||
|
||||
entities = await hass.async_add_executor_job(get_entities, onewirehub)
|
||||
entities = await hass.async_add_executor_job(get_entities, onewire_hub)
|
||||
async_add_entities(entities, True)
|
||||
|
||||
|
||||
def get_entities(onewirehub: OneWireHub) -> list[OneWireBinarySensor]:
|
||||
def get_entities(onewire_hub: OneWireHub) -> list[OneWireBinarySensor]:
|
||||
"""Get a list of entities."""
|
||||
if not onewirehub.devices:
|
||||
if not onewire_hub.devices:
|
||||
return []
|
||||
|
||||
entities: list[OneWireBinarySensor] = []
|
||||
for device in onewirehub.devices:
|
||||
for device in onewire_hub.devices:
|
||||
family = device.family
|
||||
device_id = device.id
|
||||
device_type = device.type
|
||||
@ -128,7 +128,7 @@ def get_entities(onewirehub: OneWireHub) -> list[OneWireBinarySensor]:
|
||||
device_file=device_file,
|
||||
device_info=device_info,
|
||||
name=name,
|
||||
owproxy=onewirehub.owproxy,
|
||||
owproxy=onewire_hub.owproxy,
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -19,7 +19,7 @@ async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: ConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
onewirehub: OneWireHub = hass.data[DOMAIN][entry.entry_id]
|
||||
onewire_hub: OneWireHub = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
return {
|
||||
"entry": {
|
||||
@ -27,7 +27,7 @@ async def async_get_config_entry_diagnostics(
|
||||
"data": async_redact_data(entry.data, TO_REDACT),
|
||||
"options": {**entry.options},
|
||||
},
|
||||
"devices": [asdict(device_details) for device_details in onewirehub.devices]
|
||||
if onewirehub.devices
|
||||
"devices": [asdict(device_details) for device_details in onewire_hub.devices]
|
||||
if onewire_hub.devices
|
||||
else [],
|
||||
}
|
||||
|
@ -367,23 +367,23 @@ async def async_setup_entry(
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up 1-Wire platform."""
|
||||
onewirehub = hass.data[DOMAIN][config_entry.entry_id]
|
||||
onewire_hub = hass.data[DOMAIN][config_entry.entry_id]
|
||||
entities = await hass.async_add_executor_job(
|
||||
get_entities, onewirehub, config_entry.options
|
||||
get_entities, onewire_hub, config_entry.options
|
||||
)
|
||||
async_add_entities(entities, True)
|
||||
|
||||
|
||||
def get_entities(
|
||||
onewirehub: OneWireHub, options: MappingProxyType[str, Any]
|
||||
onewire_hub: OneWireHub, options: MappingProxyType[str, Any]
|
||||
) -> list[OneWireSensor]:
|
||||
"""Get a list of entities."""
|
||||
if not onewirehub.devices:
|
||||
if not onewire_hub.devices:
|
||||
return []
|
||||
|
||||
entities: list[OneWireSensor] = []
|
||||
assert onewirehub.owproxy
|
||||
for device in onewirehub.devices:
|
||||
assert onewire_hub.owproxy
|
||||
for device in onewire_hub.devices:
|
||||
family = device.family
|
||||
device_type = device.type
|
||||
device_id = device.id
|
||||
@ -403,7 +403,7 @@ def get_entities(
|
||||
if description.key.startswith("moisture/"):
|
||||
s_id = description.key.split(".")[1]
|
||||
is_leaf = int(
|
||||
onewirehub.owproxy.read(
|
||||
onewire_hub.owproxy.read(
|
||||
f"{device_path}moisture/is_leaf.{s_id}"
|
||||
).decode()
|
||||
)
|
||||
@ -427,7 +427,7 @@ def get_entities(
|
||||
device_file=device_file,
|
||||
device_info=device_info,
|
||||
name=name,
|
||||
owproxy=onewirehub.owproxy,
|
||||
owproxy=onewire_hub.owproxy,
|
||||
)
|
||||
)
|
||||
return entities
|
||||
|
@ -150,20 +150,20 @@ async def async_setup_entry(
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up 1-Wire platform."""
|
||||
onewirehub = hass.data[DOMAIN][config_entry.entry_id]
|
||||
onewire_hub = hass.data[DOMAIN][config_entry.entry_id]
|
||||
|
||||
entities = await hass.async_add_executor_job(get_entities, onewirehub)
|
||||
entities = await hass.async_add_executor_job(get_entities, onewire_hub)
|
||||
async_add_entities(entities, True)
|
||||
|
||||
|
||||
def get_entities(onewirehub: OneWireHub) -> list[OneWireSwitch]:
|
||||
def get_entities(onewire_hub: OneWireHub) -> list[OneWireSwitch]:
|
||||
"""Get a list of entities."""
|
||||
if not onewirehub.devices:
|
||||
if not onewire_hub.devices:
|
||||
return []
|
||||
|
||||
entities: list[OneWireSwitch] = []
|
||||
|
||||
for device in onewirehub.devices:
|
||||
for device in onewire_hub.devices:
|
||||
family = device.family
|
||||
device_type = device.type
|
||||
device_id = device.id
|
||||
@ -185,7 +185,7 @@ def get_entities(onewirehub: OneWireHub) -> list[OneWireSwitch]:
|
||||
device_file=device_file,
|
||||
device_info=device_info,
|
||||
name=name,
|
||||
owproxy=onewirehub.owproxy,
|
||||
owproxy=onewire_hub.owproxy,
|
||||
)
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user