fluffykraken / bvg-sensor

provides the time in minutes until the next departure
The Unlicense
18 stars 12 forks source link

Can't write to files..permission? #3

Closed marcianito closed 5 years ago

marcianito commented 5 years ago

First of all: great add on! absolutely necessary :)

sadly for me it's not working so far. I was getting the newest release (some hours ago) and set everything up as you explained.

The files lies in .homeassistant/custom_components/sensor/bvgsensor.py Data folder (file_path) under .homeassistant/data_bvg; both have homeassistant:homeassistant rights. I am using HA version 0.86, so this should also be fine.

The following error is thrown by all of my test stations, here shown for your "rosa luxemburg"-example..any ideas? Help would be highly appreciated!

Error: Update for sensor.u2_rosa_luxemburg_platz fails

Traceback (most recent call last): File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state await self.async_device_update() File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update await self.hass.async_add_executor_job(self.update) File "/usr/lib/python3.5/asyncio/futures.py", line 380, in iter yield self # This tells Task to wait for completion. File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup future.result() File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result raise self._exception File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run result = self.fn(*self.args, **self.kwargs) File "/home/homeassistant/.homeassistant/custom_components/sensor/bvgsensor.py", line 148, in update self.fetchDataFromURL File "/home/homeassistant/.homeassistant/custom_components/sensor/bvgsensor.py", line 161, in fetchDataFromURL self.data = json.loads(source) File "/usr/lib/python3.5/json/init.py", line 312, in loads s.class.name)) TypeError: the JSON object must be str, not 'bytes'

fluffykraken commented 5 years ago

I will take a look, could you please post your config and your Python version? I will upload a new version within the next hour for you to test (0.3.4)

fluffykraken commented 5 years ago

Just uploaded a test version for you. You can find the file here: https://github.com/fluffykraken/bvg-sensor/blob/issue_%233/bvgsensor.py

marcianito commented 5 years ago

hey..thanks for beeing so quick!

output of python --version: Python 2.7.13

here are my entries in configuration.yaml, one was copy paste of yours with an adaption of the "file-path": sensor:

I will get and test your sent version now!

marcianito commented 5 years ago

This is my error code (for me it seems somewhat similar!?): Why is it never trying to access (put the .json) in the within "file-path" specified directory?

Traceback (most recent call last): File "/home/homeassistant/.homeassistant/custom_components/sensor/bvgsensor.py", line 166, in fetchDataFromURL with urlopen(self.url) as response: File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen return opener.open(url, data, timeout) File "/usr/lib/python3.5/urllib/request.py", line 472, in open response = meth(req, response) File "/usr/lib/python3.5/urllib/request.py", line 582, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python3.5/urllib/request.py", line 510, in error return self._call_chain(args) File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain result = func(args) File "/usr/lib/python3.5/urllib/request.py", line 590, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 503: Service Unavailable During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/homeassistant/.homeassistant/custom_components/sensor/bvgsensor.py", line 191, in fetchDataFromFile with open("{}{}".format(self.file_path, self.file_name), 'r') as fd: FileNotFoundError: [Errno 2] No such file or directory: '/home/homeassistant/.homeassistant/bvg_900000069271.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state await self.async_device_update() File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 349, in async_device_update await self.hass.async_add_executor_job(self.update) File "/usr/lib/python3.5/asyncio/futures.py", line 380, in iter yield self # This tells Task to wait for completion. File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup future.result() File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result raise self._exception File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run result = self.fn(*self.args, **self.kwargs) File "/home/homeassistant/.homeassistant/custom_components/sensor/bvgsensor.py", line 155, in update self.fetchDataFromURL File "/home/homeassistant/.homeassistant/custom_components/sensor/bvgsensor.py", line 187, in fetchDataFromURL self.fetchDataFromFile() File "/home/homeassistant/.homeassistant/custom_components/sensor/bvgsensor.py", line 194, in fetchDataFromFile _LOGGER.error("Could not read file. Please check your configuration and read/write access for path: {}".format(self.cachePath)) AttributeError: 'Bvgsensor' object has no attribute 'cachePath'

fluffykraken commented 5 years ago

ok lets have a look....

you config for "U6 Ullstein" has a typo. It should be file_path: instead of file-path (underscore instead of hyphen). Also the file_path parameter is relative inside your homeassistant config path. So "/data_bvg/" should be enough.

A valid config would be something like:

sensor:

Although the component was written with Python 3 in mind it still may work with Python 2. Let me know if this config works.

marcianito commented 5 years ago

Hey..sry. I was away from home. Now back I fixed my typo. It didn't quite work from the start,but after like 20 hours (without changes to config), it did! :) I guess this was maybe just a problem from the bvg server. Anyways..thanks for your fix! Great that I can use it now.

Comment: while scanning through your code, shouldn't in line 180 and 194 self.cachePath be replaced by self.file_path ?

fluffykraken commented 5 years ago

Great that it is working for you. The API Endpoint was down quite a lot in the last days. You can check the status here: https://status.transport.rest/781627008 Thanks for pointing out the typo for the filepath, you are absolutly right. Will fix this in the next release.