HAClient¶
Home Assistant WebSocket and REST API client.
zigporter.ha_client.HAClient(ha_url: str, token: str, verify_ssl: bool = True)
¶
Client for Home Assistant REST and WebSocket APIs.
Most methods open a fresh WebSocket connection per call. Use
get_all_ws_data when you need several registry datasets at once — it
batches all commands on a single connection.
| PARAMETER | DESCRIPTION |
|---|---|
ha_url
|
Base URL of the Home Assistant instance
(e.g.
TYPE:
|
token
|
Long-lived access token created in your HA profile.
TYPE:
|
verify_ssl
|
Set to
TYPE:
|
Source code in src/zigporter/ha_client.py
call_service(domain: str, service: str, service_data: dict[str, Any]) -> None
async
¶
Call a Home Assistant service via WebSocket.
Source code in src/zigporter/ha_client.py
delete_entity(entity_id: str) -> None
async
¶
get_all_ws_data() -> dict[str, Any]
async
¶
Open a single WebSocket connection and fetch all registry + ZHA data.
Returns a dict with keys: zha_devices, entity_registry, device_registry, area_registry, automation_configs.
Source code in src/zigporter/ha_client.py
get_area_registry() -> list[dict[str, Any]]
async
¶
get_automation_configs() -> list[dict[str, Any]]
async
¶
Fetch automation configurations. Returns [] if unsupported.
get_config_entries() -> list[dict[str, Any]]
async
¶
Fetch all config entries (includes helpers like min_max, template, group).
Returns [] if unsupported.
Source code in src/zigporter/ha_client.py
get_device_registry() -> list[dict[str, Any]]
async
¶
get_entities_for_device(device_id: str) -> list[dict[str, Any]]
async
¶
Return full entity registry entries for a given HA device.
Source code in src/zigporter/ha_client.py
get_entity_ids_for_device(device_id: str) -> list[str]
async
¶
Return all entity IDs registered to a given HA device.
Source code in src/zigporter/ha_client.py
get_entity_registry() -> list[dict[str, Any]]
async
¶
get_lovelace_config(url_path: str | None = None) -> dict[str, Any] | None
async
¶
Fetch Lovelace config for one dashboard. url_path=None → default dashboard.
Tries WebSocket first with force=True to bypass HA's in-memory cache. Falls back to REST API if the WS command fails.
Returns the YAML_MODE sentinel (check with is_yaml_mode()) when HA confirms the dashboard is in YAML mode. Returns None on other fetch failures.
Source code in src/zigporter/ha_client.py
get_panels() -> dict[str, Any]
async
¶
Fetch all registered frontend panels. Returns {} if unsupported.
get_scenes() -> list[dict[str, Any]]
async
¶
Fetch scene configurations. Returns [] if unsupported.
get_scripts() -> list[dict[str, Any]]
async
¶
Fetch UI-managed script configurations. Returns [] if unsupported.
get_stale_check_data() -> dict[str, Any]
async
¶
Batch-fetch device registry, entity registry, and area registry.
Opens a single WebSocket connection and fires three commands sequentially.
Returns a dict with keys: device_registry, entity_registry,
area_registry.
Source code in src/zigporter/ha_client.py
get_states() -> list[dict[str, Any]]
async
¶
Fetch all entity states via REST API.
Source code in src/zigporter/ha_client.py
get_z2m_config_entry_id() -> str | None
async
¶
Find the config entry ID for the Zigbee2MQTT integration.
Looks for an entry with domain 'mqtt' whose title contains 'zigbee2mqtt' (case-insensitive). Returns the entry_id, or None if not found.
Source code in src/zigporter/ha_client.py
get_z2m_device_id(ieee: str) -> str | None
async
¶
Find the HA device_id for a Z2M-paired device by IEEE address.
Z2M registers devices with MQTT identifiers like 'zigbee2mqtt_0x
Source code in src/zigporter/ha_client.py
get_zha_devices() -> list[dict[str, Any]]
async
¶
Fetch all ZHA devices via WebSocket (REST endpoint removed in HA 2025+).
reload_config_entry(entry_id: str) -> None
async
¶
remove_device(device_id: str) -> None
async
¶
Remove a device entry from the HA device registry.
remove_zha_device(ieee: str) -> None
async
¶
rename_device_name(device_id: str, name_by_user: str) -> None
async
¶
Set the user-facing name for a device in the HA device registry.
Source code in src/zigporter/ha_client.py
rename_entity_id(current_entity_id: str, new_entity_id: str) -> None
async
¶
Rename an entity ID in the HA entity registry.
Source code in src/zigporter/ha_client.py
save_lovelace_config(config: dict[str, Any], url_path: str | None = None) -> None
async
¶
Save (overwrite) a Lovelace dashboard config.
Source code in src/zigporter/ha_client.py
update_automation(automation_id: str, config: dict[str, Any]) -> None
async
¶
Update a UI-managed automation config by ID.
Source code in src/zigporter/ha_client.py
update_config_entry_options(entry_id: str, options: dict[str, Any]) -> None
async
¶
Update a config entry's options and trigger a reload.
Source code in src/zigporter/ha_client.py
update_device_area(device_id: str, area_id: str) -> None
async
¶
Assign a device to an area in the HA device registry.
Source code in src/zigporter/ha_client.py
update_scene(scene_id: str, config: dict[str, Any]) -> None
async
¶
Update a UI-managed scene config by ID.
Source code in src/zigporter/ha_client.py
update_script(script_id: str, config: dict[str, Any]) -> None
async
¶
Update a UI-managed script config by ID.