Skip to content

Commit

Permalink
Merge pull request #365 from home-assistant-ecosystem/dev
Browse files Browse the repository at this point in the history
0.9.3
  • Loading branch information
fabaff committed Apr 6, 2021
2 parents ea86a90 + 5db81b8 commit ba6e191
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 284 deletions.
6 changes: 3 additions & 3 deletions homeassistant_cli/config.py
Expand Up @@ -53,7 +53,7 @@ def _locate_ha() -> Optional[str]:
if listener.services:
if len(listener.services) > 1:
_LOGGING.warning(
"Found multiple Home Assistants at %s",
"Found multiple Home Assistant instances at %s",
", ".join(listener.services),
)
_LOGGING.warning("Use --server to explicitly specify one.")
Expand Down Expand Up @@ -85,7 +85,7 @@ def resolve_server(ctx: Any) -> str: # noqa: F821
if ctx.server == "auto":

if "HASSIO_TOKEN" in os.environ and "HASS_TOKEN" not in os.environ:
ctx.resolved_server = const.DEFAULT_HASSIO_SERVER
ctx.resolved_server = const.DEFAULT_SERVER_MDNS
else:
if not ctx.resolved_server and "pytest" in sys.modules:
ctx.resolved_server = const.DEFAULT_SERVER
Expand Down Expand Up @@ -152,7 +152,7 @@ def __repr__(self) -> str:
"verbose": self.verbose,
}

return "<Configuration({})".format(view)
return f"<Configuration({view})"

def resolve_server(self) -> str:
"""Return resolved server (after resolving if needed)."""
Expand Down
4 changes: 2 additions & 2 deletions homeassistant_cli/const.py
@@ -1,11 +1,11 @@
"""Constants used by Home Assistant CLI (hass-cli)."""
PACKAGE_NAME = 'homeassistant_cli'

__version__ = '0.9.2'
__version__ = '0.9.3'

AUTO_SERVER = 'auto'
DEFAULT_SERVER = 'http://localhost:8123'
DEFAULT_HASSIO_SERVER = 'http://homeassistant:8123'
DEFAULT_SERVER_MDNS = 'http://homeassistant.local:8123'
DEFAULT_TIMEOUT = 5
DEFAULT_OUTPUT = 'json' # TODO: Have default be human table relevant output

Expand Down
16 changes: 16 additions & 0 deletions homeassistant_cli/hassconst.py
Expand Up @@ -3,6 +3,22 @@
Copy of recent homeassistant.const to make hass-cli run
without installing Home Assistant itself.
"""
# Home Assistant WS constants

# Websocket API
WS_TYPE_DEVICE_REGISTRY_LIST = "config/device_registry/list"
WS_TYPE_AREA_REGISTRY_LIST = "config/area_registry/list"
WS_TYPE_AREA_REGISTRY_CREATE = "config/area_registry/create"
WS_TYPE_AREA_REGISTRY_DELETE = "config/area_registry/delete"
WS_TYPE_AREA_REGISTRY_UPDATE = "config/area_registry/update"
WS_TYPE_DEVICE_REGISTRY_UPDATE = "config/device_registry/update"
WS_TYPE_ENTITY_REGISTRY_LIST = "config/entity_registry/list"
WS_TYPE_ENTITY_REGISTRY_GET = "config/entity_registry/get"
WS_TYPE_ENTITY_REGISTRY_UPDATE = "config/entity_registry/update"
WS_TYPE_ENTITY_REGISTRY_REGISTRY = "config/entity_registry/remove"

###############################################################################
# Home Assistant constants

# Format for platform files
PLATFORM_FORMAT = "{platform}.{domain}"
Expand Down
6 changes: 3 additions & 3 deletions homeassistant_cli/plugins/area.py
Expand Up @@ -37,9 +37,9 @@ def listcmd(ctx: Configuration, areafilter: str):
else:
areafilterre = re.compile(areafilter) # type: Pattern

for device in areas:
if areafilterre.search(device['name']):
result.append(device)
for area in areas:
if areafilterre.search(area['name']):
result.append(area)

cols = [('ID', 'area_id'), ('NAME', 'name')]

Expand Down
11 changes: 10 additions & 1 deletion homeassistant_cli/plugins/device.py
Expand Up @@ -28,6 +28,8 @@ def listcmd(ctx: Configuration, devicefilter: str):
"""List all devices from Home Assistant."""
ctx.auto_output("table")

areas = api.get_areas(ctx)

devices = api.get_devices(ctx)

result = [] # type: List[Dict]
Expand All @@ -40,12 +42,19 @@ def listcmd(ctx: Configuration, devicefilter: str):
if devicefilterre.search(device['name']):
result.append(device)

for device in devices:
area = next(
(a for a in areas if a['area_id'] == device['area_id']), None
)
if area:
device['area_name'] = area['name']

cols = [
('ID', 'id'),
('NAME', 'name'),
('MODEL', 'model'),
('MANUFACTURER', 'manufacturer'),
('AREA', 'area_id'),
('AREA', 'area_name'),
]

ctx.echo(
Expand Down

0 comments on commit ba6e191

Please sign in to comment.