myTselection / youfone_be

Yoin.be Youfone.nl Home Assistant custom component HACS to get Yoin / Youfone mobile phone subscription and usage details for Belgium and Netherlands.
MIT License
3 stars 1 forks source link

Error while setting up youfone_be platform for sensor #2

Closed tjorim closed 1 year ago

tjorim commented 1 year ago

Tested with version 1.0.1:

Logger: homeassistant.components.sensor
Source: custom_components/youfone_be/utils.py:56
Integration: Sensor (documentation, issues)
First occurred: 2:20:16 PM (1 occurrences)
Last logged: 2:20:16 PM

Error while setting up youfone_be platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 289, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/youfone_be/sensor.py", line 69, in async_setup_entry
    await dry_setup(hass, config, async_add_devices)
  File "/config/custom_components/youfone_be/sensor.py", line 44, in dry_setup
    await componentData._init()
  File "/config/custom_components/youfone_be/sensor.py", line 100, in _init
    self._user_details = await self._hass.async_add_executor_job(lambda: self._session.login(self._username, self._password))
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/youfone_be/sensor.py", line 100, in <lambda>
    self._user_details = await self._hass.async_add_executor_job(lambda: self._session.login(self._username, self._password))
  File "/config/custom_components/youfone_be/utils.py", line 56, in login
    self.msisdn = self.userdetails.get('Object').get('Customers')[0].get('Msisdn')
AttributeError: 'NoneType' object has no attribute 'get'
myTselection commented 1 year ago

strange, this youfone integration is running very stable for me. Could you please enable debug logging and get info logged in line with "youfone.be login post result status code" within the home-assistant.log file To enable debug logging, you may need to add below config in HA configuration.yaml:

logger:
        default: debug
tjorim commented 1 year ago
2023-01-22 19:19:57.637 INFO (MainThread) [custom_components.youfone_be]
-------------------------------------------------------------------
Youfone.be
Version: 1.0.1
This is a custom component
If you have any issues with this you need to open an issue here:
https://github.com/myTselection/youfone_be/issues
-------------------------------------------------------------------
2023-01-22 19:19:57.939 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.youfone_be
2023-01-22 19:19:58.814 INFO (MainThread) [custom_components.youfone_be.sensor] async_setup_entry Youfone.be
2023-01-22 19:19:58.815 INFO (MainThread) [custom_components.youfone_be.sensor] Fetching intit stuff for Youfone.be
2023-01-22 19:19:58.995 DEBUG (SyncWorker_6) [custom_components.youfone_be.utils] youfone.be login post result status code: 200, response: {"Message":null,"ResultCode":1}
2023-01-22 19:19:58.996 DEBUG (SyncWorker_6) [custom_components.youfone_be.utils] youfone.be login header: {'Server': 'nginx', 'Date': 'Sun, 22 Jan 2023 18:19:58 GMT', 'Content-Type': 'application/json', 'Content-Length': '31', 'Connection': 'keep-alive', 'Cache-Control': 'private', 'X-AspNet-Version': '4.0.30319', 'X-Robots-Tag': 'noindex', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept, SecurityKey', 'Access-Control-Allow-Methods': 'POST,GET,OPTIONS,PUT,DELETE', 'Access-Control-Expose-Headers': 'SecurityKey', 'Access-Control-Max-Age': '600', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains', 'X-XSS-Protection': '1; mode=block', 'X-Frame-Options': 'SAMEORIGIN', 'Content-Security-Policy': "frame-ancestors 'none';"}
2023-01-22 19:19:59.015 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.mqtt
2023-01-22 19:19:59.380 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up youfone_be platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 289, in _async_setup_platform
await asyncio.shield(task)
File "/config/custom_components/youfone_be/sensor.py", line 69, in async_setup_entry
await dry_setup(hass, config, async_add_devices)
File "/config/custom_components/youfone_be/sensor.py", line 44, in dry_setup
await componentData._init()
File "/config/custom_components/youfone_be/sensor.py", line 100, in _init
self._user_details = await self._hass.async_add_executor_job(lambda: self._session.login(self._username, self._password))
File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/youfone_be/sensor.py", line 100, in <lambda>
self._user_details = await self._hass.async_add_executor_job(lambda: self._session.login(self._username, self._password))
File "/config/custom_components/youfone_be/utils.py", line 56, in login
self.msisdn = self.userdetails.get('Object').get('Customers')[0].get('Msisdn')
AttributeError: 'NoneType' object has no attribute 'get'
myTselection commented 1 year ago

Dear tjorim, thanks for the info.

Yet, the response you receive looks very strange and empty. youfone.be login post result status code: 200, response: {"Message":null,"ResultCode":1} Are you sure you have an active account? My login response looks like below:

youfone.be login post result status code: 200, response: {"Message":"Authorization succes","ResultCode":0,"Object":{"Customer":{"CustomerNumber":123456789,
"Email":"******@gmail.com","FirstName":"******","Gender":null,"Id":12345678,"Initials":"*","IsBusinessCustomer":false,"Language":"nl","LastName":"********","PhoneNumber":"0411111111","Prefix":null,"RoleId":2},"Customers":[{"CustomerId":123456,"C
ustomerNumber":123456789,"IsDefaultCustomer":true,"Msisdn":32411111111,"ProvisioningTypeId":1,"RoleId":2}],"CustomersCount":1}}
tjorim commented 1 year ago

My mistake, I noticed I logged in with an account that had its number migrated to another provider. Maybe add a check for an active number during the config flow?