MCPcopy
hub / github.com/hacs/integration / hacs_repositories_add

Function hacs_repositories_add

custom_components/hacs/websocket/repositories.py:143–193  ·  view source on GitHub ↗

Add custom repositoriy.

(
    hass: HomeAssistant,
    connection: websocket_api.ActiveConnection,
    msg: dict[str, Any],
)

Source from the content-addressed store, hash-verified

141@websocket_api.require_admin
142@websocket_api.async_response
143async def hacs_repositories_add(
144 hass: HomeAssistant,
145 connection: websocket_api.ActiveConnection,
146 msg: dict[str, Any],
147) -> None:
148 """Add custom repositoriy."""
149 hacs: HacsBase = hass.data.get(DOMAIN)
150 repository = regex.extract_repository_from_url(msg["repository"])
151 category = msg["category"]
152
153 if repository is None:
154 return
155
156 if repository in hacs.common.skip:
157 hacs.common.skip.remove(repository)
158
159 if renamed := hacs.common.renamed_repositories.get(repository):
160 repository = renamed
161
162 if category not in hacs.common.categories:
163 hacs.log.error("%s is not a valid category for %s", category, repository)
164
165 elif not hacs.repositories.get_by_full_name(repository):
166 try:
167 await hacs.async_register_repository(
168 repository_full_name=repository,
169 category=category,
170 )
171
172 except (
173 BaseException # lgtm [py/catch-base-exception] pylint: disable=broad-except
174 ) as exception:
175 hacs.async_dispatch(
176 HacsDispatchEvent.ERROR,
177 {
178 "action": "add_repository",
179 "exception": str(sys.exc_info()[0].__name__),
180 "message": str(exception),
181 },
182 )
183
184 else:
185 hacs.async_dispatch(
186 HacsDispatchEvent.ERROR,
187 {
188 "action": "add_repository",
189 "message": f"Repository '{repository}' exists in the store.",
190 },
191 )
192
193 connection.send_message(websocket_api.result_message(msg["id"], {}))
194
195
196@websocket_api.websocket_command(

Callers

nothing calls this directly

Calls 5

getMethod · 0.80
removeMethod · 0.80
get_by_full_nameMethod · 0.80
async_dispatchMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…