Shelly - use common coordinator base class (#86262)

* Shelly - use common coordinator base class

* rename entry to device_entry

Co-authored-by: J. Nick Koston <nick@koston.org>

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Shay Levy 2023-01-20 09:43:01 +02:00 committed by GitHub
parent 3c4455c696
commit 585c4acfee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 108 additions and 164 deletions

View file

@ -44,15 +44,23 @@ def async_remove_shelly_entity(
def get_block_device_name(device: BlockDevice) -> str:
"""Naming for device."""
"""Get Block device name."""
return cast(str, device.settings["name"] or device.settings["device"]["hostname"])
def get_rpc_device_name(device: RpcDevice) -> str:
"""Naming for device."""
"""Get RPC device name."""
return cast(str, device.config["sys"]["device"].get("name") or device.hostname)
def get_device_name(device: BlockDevice | RpcDevice) -> str:
"""Get device name."""
if isinstance(device, BlockDevice):
return get_block_device_name(device)
return get_rpc_device_name(device)
def get_number_of_channels(device: BlockDevice, block: Block) -> int:
"""Get number of channels for block type."""
assert isinstance(device.shelly, dict)