Giter Club home page Giter Club logo

hass-truenas's Introduction

hacs_badge hacs hassfest

TrueNAS Integration for Home Assistant

Features

  • Virtual machines and their running state
  • Disks and their temperature

Installation

  1. Install using HACS. Or install manually by copying custom_components/truenas folder into <config_dir>/custom_components
  2. Restart Home Assistant.
  3. In the Home Assistant UI, navigate to Configuration then Integrations. Click on the add integration button at the bottom right and select TrueNAS. Fill out the options and save.
    • Host: the ip address or hostname of the TrueNAS server.
    • Username: the username used to login to the TrueNAS server.
    • Password: the password used to login to the TrueNAS server.

Using Services

truenas.jail_start

truenas.jail_stop

truenas.jail_restart

truenas.vm_start

truenas.vm_stop

truenas.vm_restart

Development

python3.9 -m venv .venv
source .venv/bin/activate

# Install Dev Requirements
pip install -r requirements-dev.txt

# One-Time Install of Commit Hooks
pre-commit install

# Run tests
python -m pytest tests

hass-truenas's People

Contributors

colemamd avatar dependabot[bot] avatar matthewflamm avatar renovate[bot] avatar sdwilsh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

hass-truenas's Issues

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Location: renovate.json
Error type: The renovate configuration file contains some invalid settings
Message: Regex Managers must contain datasourceTemplate configuration or regex group named datasource

not available in HACS list

the readme states that this integration can be installed with HACS
however, it is not available in HACS

Integration sometimes times out during startup

From time to time, the TrueNAS integration times out during startup and does not automatically recover without manual action. Manually reloading the integration fixes it, or another HA restart.

bild

2023-04-13 11:33:12.269 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry truenas.local for truenas
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/client.py", line 655, in __await_impl_timeout__
    return await self.__await_impl__()
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/client.py", line 662, in __await_impl__
    await protocol.handshake(
  File "/usr/local/lib/python3.10/site-packages/aiotruenas_client/websockets/protocol.py", line 73, in handshake
    result = await self._authenticate()
  File "/usr/local/lib/python3.10/site-packages/aiotruenas_client/websockets/protocol.py", line 200, in _authenticate
    return await self.invoke_method("auth.login_with_api_key", [self._api_key])
  File "/usr/local/lib/python3.10/site-packages/aiotruenas_client/websockets/protocol.py", line 92, in invoke_method
    recv = await recv_future
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 383, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/config/custom_components/truenas/__init__.py", line 64, in async_setup_entry
    machine = await Machine.create(
  File "/usr/local/lib/python3.10/site-packages/aiotruenas_client/websockets/machine.py", line 51, in create
    await m.connect(
  File "/usr/local/lib/python3.10/site-packages/aiotruenas_client/websockets/machine.py", line 92, in connect
    await self._connect(auth_protocol, host, secure)
  File "/usr/local/lib/python3.10/site-packages/aiotruenas_client/websockets/machine.py", line 199, in _connect
    await connect(
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/client.py", line 654, in __await_impl_timeout__
    async with asyncio_timeout(self.open_timeout):
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/async_timeout.py", line 169, in __aexit__
    self._do_exit(exc_type)
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/async_timeout.py", line 252, in _do_exit
    raise asyncio.TimeoutError
asyncio.exceptions.TimeoutError
2023-04-13 11:33:12.276 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/protocol.py", line 959, in transfer_data
    message = await self.read_message()
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/protocol.py", line 1029, in read_message
    frame = await self.read_data_frame(max_size=self.max_size)
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/protocol.py", line 1104, in read_data_frame
    frame = await self.read_frame(max_size)
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/protocol.py", line 1161, in read_frame
    frame = await Frame.read(
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/framing.py", line 68, in read
    data = await reader(2)
  File "/usr/local/lib/python3.10/asyncio/streams.py", line 707, in readexactly
    await self._wait_for_data('readexactly')
  File "/usr/local/lib/python3.10/asyncio/streams.py", line 501, in _wait_for_data
    await self._waiter
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiotruenas_client/websockets/protocol.py", line 166, in _websocket_message_handler
    async for message in self:
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/protocol.py", line 497, in __aiter__
    yield await self.recv()
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/protocol.py", line 568, in recv
    await self.ensure_open()
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/protocol.py", line 930, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: no close frame received or sent

Services do not work

I get this error

Logger: homeassistant.helpers.script.websocket_api_script
Source: custom_components/truenas/init.py:253
Integration: TrueNAS (documentation)
First occurred: 10:21:08 AM (1 occurrences)
Last logged: 10:21:08 AM

websocket_api script: Error executing script. Unexpected error for call_service at pos 1:
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/helpers/script.py", line 381, in _async_step
await getattr(self, handler)()
File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/helpers/script.py", line 584, in _async_call_service_step
await service_task
File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/core.py", line 1495, in async_call
task.result()
File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/core.py", line 1530, in _execute_service
await handler.job.target(service_call)
File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/helpers/entity_platform.py", line 691, in handle_service
await service.entity_service_call(
File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/helpers/service.py", line 663, in entity_service_call
future.result() # pop exception if have
File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/helpers/entity.py", line 896, in async_request_call
await coro
File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/helpers/service.py", line 700, in _handle_entity_call
await result
File "/home/homeassistant/.homeassistant/custom_components/truenas/init.py", line 253, in stop
await self._jail.stop(force=force)
File "/srv/homeassistant/lib/python3.9/site-packages/aiotruenas_client/websockets/jail.py", line 21, in stop
return await self._fetcher._stop_jail(self, force)
File "/srv/homeassistant/lib/python3.9/site-packages/aiotruenas_client/websockets/jail.py", line 90, in _stop_jail
job_id = await self._parent._invoke_method("jail.stop", [jail.name, force])
File "/srv/homeassistant/lib/python3.9/site-packages/aiotruenas_client/websockets/machine.py", line 183, in _invoke_method
assert not self.closed
AssertionError

Initial setup throws unknown error (maybe related to UI port settings)

Update: when I enter the https port, it does allow me to complete the setup. I can now see the disk temperatures. I think it's a good idea to mention this in the install instructions.

I have TrueNAS configured to provide the UI on port 250 through http.

I tried to set up the integration this morning through the HA UI, but I'm getting an unknown error.

Things I have tried:

  • Add the port number to the IP address
  • Use the hostname instead of IP address
  • Use the API key
  • Use username/password

Error log:

2021-04-09 10:55:24 ERROR (MainThread) [custom_components.truenas.config_flow] Unexpected exception
Traceback (most recent call last):
  File "/config/custom_components/truenas/config_flow.py", line 121, in async_step_auth_api_key
    info = await validate_input(self.hass, self._user_data)
  File "/config/custom_components/truenas/config_flow.py", line 54, in validate_input
    machine = await Machine.create(
  File "/usr/local/lib/python3.8/site-packages/aiotruenas_client/websockets/machine.py", line 43, in create
    await m.connect(
  File "/usr/local/lib/python3.8/site-packages/aiotruenas_client/websockets/machine.py", line 75, in connect
    await self._connect(auth_protocol, host, secure)
  File "/usr/local/lib/python3.8/site-packages/aiotruenas_client/websockets/machine.py", line 86, in _connect
    self._client = await websockets.connect(
  File "/usr/local/lib/python3.8/site-packages/websockets/client.py", line 535, in __await_impl__
    transport, protocol = await self._create_connection()
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 986, in create_connection
    infos = await self._ensure_resolved(
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1365, in _ensure_resolved
    return await loop.getaddrinfo(host, port, family=family, type=type,
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 825, in getaddrinfo
    return await self.run_in_executor(
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.8/socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Try again

Unload entry references invalid key

Error traceback when unloading entry:

Traceback (most recent call last):
  File "/mnt/usbdrive/homeassistant/custom/home-assistant/homeassistant/config_entr
ies.py", line 321, in async_unload
    result = await component.async_unload_entry(hass, self)  # type: ignore
  File "/mnt/usbdrive/homeassistant/custom/home-assistant/config/custom_components/
truenas/__init__.py", line 113, in async_unload_entry
    await hass.data[DOMAIN]["machine"]._client.close()
KeyError: 'machine'

Data is stored inside the entry.entry_id

hass.data[DOMAIN][entry.entry_id] = {

But it is not used in the unload

await hass.data[DOMAIN]["machine"]._client.close()

Add tests

I somewhat hesitate to suggest this, as it uses my own project, but it would help me contribute more competently if tests are added. Please feel free to decline since it is not trivial to add tests
for homeassistant code, and, more importantly, tests for custom components is not supported by homeassistant directly.

See https://github.com/MatthewFlamm/pytest-homeassistant-custom-component.

If this is okay, I can add it to your requirements and CI with a starter of tests for the config flow.

Pools as entities

Hi! You made great integration! I read aiotruenas-client and saw that you can list pools. Can you add pools to integration?

Unknown Error

Hi friends!

I install the hass-truenas by hacs, reboot HA, and go to integrations to complete the installation.
Once I have added the host IP, press submit and add the API Key, and reports me "Unknown Error".

Can some one help? there's some issue?

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/hacs.yaml
  • actions/checkout v4
.github/workflows/hassfest.yaml
  • actions/checkout v4
.github/workflows/lint.yml
  • actions/checkout v4
  • actions/setup-python v4
.github/workflows/test.yml
  • actions/checkout v4
  • actions/setup-python v4
pip_requirements
requirements-dev.txt
  • aiotruenas-client ==0.10.0
  • black ==23.10.0
  • flake8 ==6.1.0
  • isort ==5.12.0
  • pre-commit ==3.5.0
  • pytest-homeassistant-custom-component ==0.13.22
  • yamllint ==1.32.0
regex
.pre-commit-config.yaml
  • black 23.10.0
  • flake8 6.1.0
  • isort 5.12.0
  • yamllint 1.32.0
custom_components/truenas/manifest.json
  • aiotruenas-client 0.10.0

  • Check this box to trigger a request for Renovate to run again on this repository

TrueNAS scale

Hi!
I'm having issues with using your integration with TrueNAS scale. I'm wondering if it could just be the fact that I'm using Scale. But here is the error.

2021-11-13 03:18:10 ERROR (MainThread) [custom_components.truenas.config_flow] Unexpected exception
Traceback (most recent call last):
File "/usr/local/lib/python3.9/encodings/idna.py", line 165, in encode
raise UnicodeError("label empty or too long")
UnicodeError: label empty or too long
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/config/custom_components/truenas/config_flow.py", line 126, in async_step_auth_api_key
info = await validate_input(self.hass, self._user_data)
File "/config/custom_components/truenas/config_flow.py", line 54, in validate_input
machine = await Machine.create(
File "/usr/local/lib/python3.9/site-packages/aiotruenas_client/websockets/machine.py", line 48, in create
await m.connect(
File "/usr/local/lib/python3.9/site-packages/aiotruenas_client/websockets/machine.py", line 88, in connect
await self._connect(auth_protocol, host, secure)
File "/usr/local/lib/python3.9/site-packages/aiotruenas_client/websockets/machine.py", line 171, in _connect
await connect(
File "/usr/local/lib/python3.9/site-packages/websockets/legacy/client.py", line 622, in await_impl
transport, protocol = await self._create_connection()
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1017, in create_connection
infos = await self._ensure_resolved(
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1396, in _ensure_resolved
return await loop.getaddrinfo(host, port, family=family, type=type,
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 856, in getaddrinfo
return await self.run_in_executor(
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.9/socket.py", line 954, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
UnicodeError: encoding with 'idna' codec failed (UnicodeError: label empty or too long)

ConnectionResetError: Cannot write to closing transport

Hi,

Home Assistant: 2021.10.7
hacs: 1.15.2
hass-truenas: 0.21

Fresh install on my Hass server. I've set host, auth type=apikey and set the api key through Hass UI, but get the following error:

Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
resp = await self._request_handler(request)
File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 499, in _handle
resp = await handler(request)
File "/usr/local/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 119, in impl
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 220, in forwarded_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 24, in request_context_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 78, in ban_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 144, in auth_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 136, in handle
result = await result
File "/usr/src/homeassistant/homeassistant/components/hassio/http.py", line 78, in _handle
return await self._command_proxy(path, request)
File "/usr/src/homeassistant/homeassistant/components/hassio/http.py", line 116, in _command_proxy
await response.write(data)
File "/usr/local/lib/python3.9/site-packages/aiohttp/web_response.py", line 470, in write
await self._payload_writer.write(data)
File "/usr/local/lib/python3.9/site-packages/aiohttp/http_writer.py", line 107, in write
self._write(chunk)
File "/usr/local/lib/python3.9/site-packages/aiohttp/http_writer.py", line 67, in _write
raise ConnectionResetError("Cannot write to closing transport")
ConnectionResetError: Cannot write to closing transport

When I try to call my nas using curl, from my hass server, it works great (curl "https://nas.mydomain.com/api/v2.0/user" -k -X GET -H "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")

integration not available in home assistant

After adding the integration using HACS's add custom integration, I can see the integration in the HACS screen, however it is not available when trying to add the integration in home assistant's configuration=>add integration

Integration incompatible with HA 2023.4.2 because of websockets constraint

The integration stopped working after updating to HA 2023.4.2 because the websockets dependency constraint prohibits it from being installed.

2023-04-09 08:57:46.888 ERROR (SyncWorker_5) [homeassistant.util.package] Unable to install package aiotruenas-client==0.9.0: ERROR: Cannot install aiotruenas-client==0.9.0 because these package versions have conflicting dependencies.
ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts

The websockets version was bumped to 11.0.1: home-assistant/core#90901

No module named 'pyfreenas'

Hi,

I installed this integration via HACS, but I receive this error in my hass.io logs and no TrueNAS entities ever appear:

Logger: homeassistant.setup
Source: setup.py:280
First occurred: 1:14:02 AM (1 occurrences)
Last logged: 1:14:02 AM

Unable to prepare setup for platform truenas.sensor: Platform not found (No module named 'pyfreenas').

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.