Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: ‘NoneType' object is not subscriptable #26

Closed
manonstreet opened this issue Feb 26, 2020 · 16 comments
Closed

ERROR: ‘NoneType' object is not subscriptable #26

manonstreet opened this issue Feb 26, 2020 · 16 comments

Comments

@manonstreet
Copy link

I’m using 2.0.6b to test out the new feature where the Stationary zone isn’t created until first use. However on Home Assistant start, iCloud3 throws the following error:

Logger:
custom_components.icloud3.device_tracker 
First occured: 3:18:05 PM (2 occurences) 
Last logged: 3:18:06 PM

'NoneType' object is not subscriptable
Traceback (most recent call last):
  File "/config/custom_components/icloud3/device_tracker.py", line 5355, in _initialize_device_zone_fields
    first_initial = self.friendly_name.get(devicename)[0].lower()
TypeError: 'NoneType' object is not subscriptable
@manonstreet manonstreet changed the title ERROR: NoneType' object is not subscriptable ERROR: ‘NoneType' object is not subscriptable Feb 26, 2020
@gcobb321
Copy link
Owner

I've updated ic3 to 2.0.6c (or d) in the development directory. Waiting to set up stat. Zone doesn't place nice with the iOS app. New zones are not getting pushed to the iOS app so it then doesn't do any enter/exit triggers for the stat. zone. I'm now trying to create one around the home zone but get enter/exit triggers on a 1m zone passive zone for some strange reason.

Download the development version. After loading and the devices are located, do a hard reset on the iOS app to load the zones if the stat. zone is not listed on the App Config/Locations for the iOS app.

@manonstreet
Copy link
Author

I've confirmed that the version I used for testing associated with this issue is the same as the latest:
2.0.6c for device_tracker
v2.0.6b for pyicloud_ic3

I've also confirmed that the stationary zone is not showing up in my iOS app, so that is likely the cause. I'm a bit weary of doing a hard reset which will delete my mobile_app integration and all of the associated devices. I believe I can just re-add and rename all of the entities again and everything should "just work".

@gcobb321
Copy link
Owner

Working on 2.0.6d now. Ran into some things today and looking at them now. I'll be out running errands tomorrow and will give it a workout.

You don't have to do a hard reset on the ios app on HA and delete the integration as you described.. On the iphone, open the app switcher (slide up fro the bottom) and push the ios app off the top of the screen to unload it from the iphone's memory. Then open the ios app again and it will reload the zones, which will include the newly setup stationary zone.

@manonstreet
Copy link
Author

I believe everything is working as intended. My status does go into a stationary zone, and exit from that zone. The only issue I see that on HA startup, the above error is thrown.

@gcobb321
Copy link
Owner

I've uploaded iCloud3 v2.1 to the iCloud repository development v2.1 directory here. It's a prerelease that changes the Stationary Zone process. See the changelog.md file for more info. Let me know if you download it and have any problems.

@manonstreet
Copy link
Author

manonstreet commented Mar 13, 2020

I've installed the new update. Here are my observations:

  1. Stationary zones for both devices tracked by iCloud3 are created .5km north of my Home zone as noted in the Changelog.
  2. The device icon for both of those stationary zones is a person icon, and is not the first letter of the Friendly Name
  3. The following error is thrown on startup:
Logger: custom_components.icloud3.device_tracker
Source: custom_components/icloud3/device_tracker.py:5403
First occured: 10:05:49 AM (2 occurences)
Last logged: 10:05:49 AM

'NoneType' object is not subscriptable
Traceback (most recent call last):
  File "/config/custom_components/icloud3/device_tracker.py", line 5403, in _initialize_device_zone_fields
    first_initial = self.friendly_name.get(devicename)[0].lower()
TypeError: 'NoneType' object is not subscriptable
  1. In the iCloud3 Event Log card, the header does not show the Friendly Name of the user. Instead the name reads: null (devicename). For clarity, devicename is correct.

@gcobb321
Copy link
Owner

You had a devicename of maximus a while back. Is that the name that is getting the error or is it another one? What does your config parameters look like. The track devices statement changed a little to remove the sensor_name_prefix and add a friendly name. ic3 tries to figure out the friendly name using the devicename. A name on the track devices parameter line will override it. In your situation, it sounds like it isn't figuring out the friendly name from the devicename and none is specified. I'll some checks for that situation. and let you know when it is ready.

@gcobb321
Copy link
Owner

I have just updated a new version of iCloud3 that fixes the Friendly Name problem. It had to do with no first name in the iCloud account record for the device in the non-2fa account and not making the friendly name from the devicename when the tracking method was FmF. It now does not look at the iCloud account contact name but always makes it from the devicename or the name specified on the track_devices parameter line. You should be all set with this new version.

@manonstreet
Copy link
Author

That did the trick, thanks Gary.

I'd be curious how to set the friendly name using configuration parameters? Doesn't look like the docs are updated yet.

@gcobb321
Copy link
Owner

gcobb321 commented Mar 14, 2020 via email

@manonstreet
Copy link
Author

Both options are now functional. Using just - maximus makes the friendly name maximus, and -maximus > friendly_name allows me to override it.

@gcobb321
Copy link
Owner

That's good that it's working now but what changes did you make to the config to eliminate the error. I'd like to duplicate it here so the problem doesn't happen to others going forward. In the mean time, I'll mess with the iosapp method to see if I spot anything.

@manonstreet
Copy link
Author

manonstreet commented Mar 14, 2020

I have just updated a new version of iCloud3 that fixes the Friendly Name problem.

After you pushed the update related to the above comment, it started working without any configuration changes. I noted this with my comment: 'That did the trick'. Sorry if I wasn't clear.

In your follow-up comment on how to override the friendly name, you asked me to try with just using - maximus. I had already tried that and it was working successfully prior. I then tested with the friendly name override and commented that they both worked.

Also to note, I do have 2FA enabled on my icloud account. However as far as I can tell, iCloud3 doesn't attempt to login to iCloud as I do not receive a 2FA notification. I prefer it this way, since I am only using the iosapp features and am not keen on disabling 2FA. The point is, since iCloud3 isn't logging in, it wasn't able to grab my first name. I suspect the fix you applied for FmF edge cases is what corrected my problem since you noted that:

It now does not look at the iCloud account contact name but always makes it from the devicename or the name specified on the track_devices parameter line.

Hopefully that clears things up!

@manonstreet
Copy link
Author

manonstreet commented Mar 18, 2020

Version .107 is bringing some new errors with the latest build. On start I see the following:

2020-03-18 19:00:27 INFO (SyncWorker_7) [custom_components.icloud3.device_tracker] None(None) Initializing v2.1 > Stage 1, Preparing iCloud3
2020-03-18 19:00:27 INFO (SyncWorker_7) [custom_components.icloud3.device_tracker] None(None) Set up Zones-
2020-03-18 19:00:27 ERROR (SyncWorker_7) [custom_components.icloud3.device_tracker] float() argument must be a string or a number, not 'NoneType'
Traceback (most recent call last):
  File "/config/custom_components/icloud3/device_tracker.py", line 940, in restart_icloud
    self._initialize_zone_tables()
  File "/config/custom_components/icloud3/device_tracker.py", line 5242, in _initialize_zone_tables
    self.zone_home_radius_km = float(self.zone_radius_km.get(HOME))
TypeError: float() argument must be a string or a number, not 'NoneType'

...

2020-03-18 19:00:27 ERROR (SyncWorker_7) [custom_components.icloud3.device_tracker] 'Icloud' object has no attribute 'waze_history_data_used_flag'
Traceback (most recent call last):
  File "/config/custom_components/icloud3/device_tracker.py", line 1081, in restart_icloud
    self._initialize_device_zone_fields(devicename)
  File "/config/custom_components/icloud3/device_tracker.py", line 5395, in _initialize_device_zone_fields
    self.waze_history_data_used_flag[devicename_zone] = False
AttributeError: 'Icloud' object has no attribute 'waze_history_data_used_flag'

...

2020-03-18 19:01:10 ERROR (SyncWorker_10) [custom_components.icloud3.device_tracker] ►►INTERNAL ERROR-RETRYING (_determine_interval:SetLocation-float() argument must be a string or a number, not 'NoneType')
2020-03-18 19:01:10 INFO (SyncWorker_15) [homeassistant.loader] Loaded august from homeassistant.components.august
2020-03-18 19:01:10 INFO (SyncWorker_6) [homeassistant.loader] Loaded tplink from homeassistant.components.tplink
2020-03-18 19:01:10 ERROR (SyncWorker_10) [custom_components.icloud3.device_tracker] 'Icloud' object has no attribute 'stat_zone_base_lat'
Traceback (most recent call last):
  File "/config/custom_components/icloud3/device_tracker.py", line 1789, in _update_device_iosapp_trigger
    self._update_last_latitude_longitude(devicename, latitude, longitude, 1844)
  File "/config/custom_components/icloud3/device_tracker.py", line 4638, in _update_last_latitude_longitude
    elif latitude == self.stat_zone_base_lat and longitude == self.stat_zone_base_long:
AttributeError: 'Icloud' object has no attribute 'stat_zone_base_lat'

...

2020-03-18 19:01:31 ERROR (SyncWorker_7) [custom_components.icloud3.device_tracker] '>' not supported between instances of 'NoneType' and 'int'
Traceback (most recent call last):
  File "/config/custom_components/icloud3/device_tracker.py", line 1988, in _polling_loop_15_sec_icloud
    self._request_iosapp_location_update(devicename)
  File "/config/custom_components/icloud3/device_tracker.py", line 2728, in _request_iosapp_location_update
    self.max_iosapp_locate_cnt):
TypeError: '>' not supported between instances of 'NoneType' and 'int'
2020-03-18 19:01:31 INFO (MainThread) [homeassistant.components.mobile_app.notify] mobile_app push notification rate limits for Maximus: 5 sent, 150 allowed, 0 errors, resets in 0:58:28
2020-03-18 19:01:31 ERROR (MainThread) [homeassistant.util.logging] Exception in update_data when dispatching 'mobile_app_location_update_089871a899ac40d2a2fddf0b3a884094': ({'gps': [40.447174072265625, -74.85114119160559], 'battery': 41, 'gps_accuracy': 65, 'vertical_accuracy': 10, 'altitude': 77.79744720458984},)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/mobile_app/device_tracker.py", line 151, in update_data
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 297, in async_write_ha_state
    self._async_write_ha_state()  # type: ignore
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 320, in _async_write_ha_state
    state = self.state
  File "/usr/src/homeassistant/homeassistant/components/device_tracker/config_entry.py", line 105, in state
    self.hass, self.latitude, self.longitude, self.location_accuracy
  File "/usr/src/homeassistant/homeassistant/components/zone/__init__.py", line 102, in async_active_zone
    zone.attributes[ATTR_LATITUDE],
KeyError: 'latitude'

2020-03-18 19:01:35 ERROR (SyncWorker_6) [custom_components.icloud3.device_tracker] unsupported operand type(s) for *: 'NoneType' and 'int'
Traceback (most recent call last):
  File "/config/custom_components/icloud3/device_tracker.py", line 1503, in _polling_loop_5_sec_device
    if (dist_from_zone_m >= current_zone_radius_m * 2 and
TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'
2020-03-18 19:01:35 ERROR (SyncWorker_6) [custom_components.icloud3.device_tracker] Device Update Error, Error=<class 'ValueError'>
2020-03-18 19:01:40 ERROR (SyncWorker_8) [custom_components.icloud3.device_tracker] ►►INTERNAL ERROR-RETRYING (_determine_interval:SetLocation-float() argument must be a string or a number, not 'NoneType')
2020-03-18 19:01:40 ERROR (SyncWorker_8) [custom_components.icloud3.device_tracker] 'Icloud' object has no attribute 'stat_zone_base_lat'
Traceback (most recent call last):
  File "/config/custom_components/icloud3/device_tracker.py", line 1789, in _update_device_iosapp_trigger
    self._update_last_latitude_longitude(devicename, latitude, longitude, 1844)
  File "/config/custom_components/icloud3/device_tracker.py", line 4638, in _update_last_latitude_longitude
    elif latitude == self.stat_zone_base_lat and longitude == self.stat_zone_base_long:
AttributeError: 'Icloud' object has no attribute 'stat_zone_base_lat'

NOTE: I tried reverting iCloud3 to the latest stable version of 2.05; however I still see these errors.

@gcobb321
Copy link
Owner

gcobb321 commented Mar 19, 2020

The first error is occuring getting the radius of the Home zone, which defaults to 100m. Check Developer tools>States to see if there is a zone entity named Home and what the radius and location is. All of the other errors are the result of not setting up the Home zone within iCloud3 correctly. Have you set it up but called it another name?

Get the latest development version from the development v2.1 directory. I just updated to 0.107.0 and iCloud3 loaded ok. I had added some additional error checking when zones are loaded. Be sure to update the iCloud3-event-log-card too. The changeling file lists all the updates.

@manonstreet
Copy link
Author

This was actually a home assistant issue corrected in .107.1. None of my zones were loading correctly until I performed an update.

I have re-redeployed 2.1rc4. All appears to be working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants