burnnat / ha-hdhomerun

HDHomeRun integration for Home Assistant.
MIT License
15 stars 6 forks source link

Could not get firmware version. #7

Open Radeon24 opened 4 years ago

Radeon24 commented 4 years ago

Hello, I have an issue with my HDHR5-4DT wich has the latest firmware 20200225 :

  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 179, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/config/custom_components/hdhomerun/sensor.py", line 47, in async_setup_entry
    'sw_version': adapter.get_version(),
  File "/usr/local/lib/python3.7/site-packages/hdhr/adapter.py", line 335, in get_version
    raise error_for_result(result, message)
ConnectionError: Could not get firmware version (-1).

I am using the master branch via HACS on HassIO.

Thank you.

burnnat commented 4 years ago

Thanks for the report. A status of -1 from the libhdhomerun library indicates a general "connection failure" so unfortunately there's not of lot of info to go on. If you have the hdhomerun_config command-line utility wherever HA is running I would check whether you are able to connect that way - and if not, that would seem to point to an issue at the network level, maybe a firewall or something.

It would be possible to make some changes and keep going with an empty firmware version if the API call fails, but I have a feeling that the same connection errors will come up again later when querying the actual tuner status.

Radeon24 commented 4 years ago

I've just install hdhomerun_config on my HA host and all seems to be fine :

alfred@alfred:~/hdhomerun/libhdhomerun$ ./hdhomerun_config 10.42.20.216 get /lineup/scan
state=complete progress=100% found=40
alfred@alfred:~/hdhomerun/libhdhomerun$ ./hdhomerun_config 10.42.20.216 get /sys/hwmodel
HDHR5-4DT
alfred@alfred:~/hdhomerun/libhdhomerun$ ./hdhomerun_config 10.42.20.216 get /sys/model
hdhomerun5_dvbt
alfred@alfred:~/hdhomerun/libhdhomerun$ ./hdhomerun_config 10.42.20.216 get /sys/version
20200225

From the HassIO container it's okay too :+1:

config $ hdhomerun_config 10.42.20.216 get /sys/version
20200225
config $ ifconfig
eth0      Link encap:Ethernet  HWaddr 02:42:AC:1E:21:04
          inet addr:172.30.33.4  Bcast:172.30.33.255  Mask:255.255.254.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:32495 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1158 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:4718688 (4.5 MiB)  TX bytes:758107 (740.3 KiB)

And this is my configuration in Home Assistant :

hdhomerun:
  sensor:
    - host: 10.42.20.216

So, I don't understand why there is this error...

burnnat commented 4 years ago

Well that is puzzling. 🤔 I'll take a look at the libhdhomerun source to look for some other ideas, otherwise I guess we can make the firmware version optional and see what happens.

mheppner commented 3 years ago

I'm not very good with ctypes and couldn't really understand the hdhr library, but I've narrowed down why this is happening (maybe?) - not sure if this helps or not:


https://github.com/burnnat/ha-hdhomerun/blob/c90619009fb257bb50ff7092258cd60a24b77566/custom_components/hdhomerun/sensor.py#L25

that gives a list of <hdhr.types.TYPE_hdhomerun_discover_device_t> objects which is used to create the adapter:

https://github.com/burnnat/ha-hdhomerun/blob/c90619009fb257bb50ff7092258cd60a24b77566/custom_components/hdhomerun/sensor.py#L34-L38

the error described in this issue is encountered with that adapter. But things seem to work fine if I create the adapter from the IP address directly, using nice_ip instead of nice_device_id:

>>> device = HdhrUtility.discover_find_devices_custom(ip='192.168.1.100')
>>> ip_adapter = HdhrDeviceQuery(HdhrUtility.device_create_from_str(device.nice_ip))  # instead of device.nice_device_id
>>> ip_adapter.get_version()
'20200907'
>>> ip_adapter.get_model_str()
'hdhomerun4_atsc'
>>> ip_adapter.get_tuner_streaminfo()
[]
>>> ip_adapter.get_tuner_program()
'0'
>>> status, raw_data = ip_adapter.get_tuner_status()
(<hdhr.types.TYPE_hdhomerun_tuner_status_t object at 0x801a16bc0>, b'ch=none lock=none ss=0 snq=0 seq=0 bps=0 pps=0')
>>> status.nice_channel
'none'

to confirm, using the nice_device_id instead:

>>> id_adapter = HdhrDeviceQuery(HdhrUtility.device_create_from_str(device.nice_device_id))
>>> id_adapter.get_version()
Could not get firmware version (-1).
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/home/hass/env/lib/python3.8/site-packages/hdhr/adapter.py", line 335, in get_version
    raise error_for_result(result, message)
ConnectionError: Could not get firmware version (-1).
>>> id_adapter.get_model_str()  # returns None
>>> id_adapter.get_tuner_streaminfo()
Could not get tuner streaminfo (-1).
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/home/hass/env/lib/python3.8/site-packages/hdhr/adapter.py", line 257, in get_tuner_streaminfo
    raise error_for_result(result, message)
ConnectionError: Could not get tuner streaminfo (-1).
>>> id_adapter.get_tuner_program()
Could not get tuner program (-1).
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/home/hass/env/lib/python3.8/site-packages/hdhr/adapter.py", line 288, in get_tuner_program
    raise error_for_result(result, message)
ConnectionError: Could not get tuner program (-1).