Skip to content

Commit

Permalink
iCloud3 v3.0, Beta 20
Browse files Browse the repository at this point in the history
  • Loading branch information
gcobb321 committed Jul 31, 2023
1 parent a85e902 commit 055f541
Show file tree
Hide file tree
Showing 40 changed files with 1,181 additions and 742 deletions.
38 changes: 29 additions & 9 deletions custom_components/icloud3/ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
Beta 19.2 - 7/10/2023
...................
1. Bug Fix - Fixed a problem displaying the iCloud3 Configure Settings screen on an iPad or iPhone.
2. Bug Fix - Fixed a problem requesting a new Apple Verification code from the Enter/Request Apple Verification code screen when it was selected from the HA Notifications > iCloud3 Reconfigure.
3. Sensor tweaks:
1. `[devicename]_arrival_time` - Changed the icon to better show when the device was in the zone (house/map icon solid = arrived) or when you would arrive (house/map icon not solid = calculated arrival time).
2. `[devicename]_zone_distance`, `[devicename]_home_distance` - Changed the icon to show if you are going towards Home, away from Home or at Home.
beta 20 - 7/29/2023 - THE LAST BETA BEFORE RELEASE CANDIDATE 1 (I HOPE)
...............................
1. Bug Fixes
1. Fixed a problem displaying the iCloud3 Configure Settings screen on an iPad or iPhone from the iOS App.
2. Fixed a problem requesting a new Apple Verification code from the Enter/Request Apple Verification code screen when it was selected from the HA Notifications > iCloud3 Reconfigure.
3. Fixed a problem logging into the iCloud Account after getting an Invalid iCloud Account username/passwor error.
2. Device Tracker State Value Source parameter (New parameter) - The Device tracker state value is generated by HA based on the gps coordinates. When the device's location is updated, HA uses the lat/long to determine if that location is in one of it's zones. If it is in a zone, the state is set to 'home' if it is in the Home Zone or the zone's friendly name if it is in another zone. It is set to 'not_home' if it is not in a zone. This does not take the gps accuracy into consideration and gps wandering will take it out of the zone and set it to 'not_home'. iCloud3 overcomes this by creating it's own [devicename]_zone sensor (zone entity name) and [devicename]_zone_fname sensor (zone friendly name-the one HA uses and displays).

This new parameter lets you select the state value to use:
1. iCloud3 Zone Friendly Name
2. iCloud3 Zone Display Name used on the Event Log
3. HA zone based on the gps coordinates.

Note: When iCloud3 is restarted and the device is in a Stationary Zone, the HA zone information is not updated on a timely basis so iCloud3 and the HA App on the devices still have the Stationary Zone information where HA may not. iCloud3 and the iOS App put the device in the Station Zone and HA sets it's state value to 'not_home'. This is not resolved until the next location is requested. To solve this, iCloud3 always sets the state value to the Stationary Zone friendly name when it is in a Stationary Zone.
3. Stationary Zone:
1. Found that the Stationary Zone timer was being reset when an old location had been detected and the location update resulted in a good location. This delayed a device from moving into a Stationary Zone until it's still time interval was reached again 8-minutes from now. This would happen again if the location was old again the next time it was checked, further delaying a device from moving into a Stationary Zone. This has been fixed.
2. Moving into a Stationary Zone will now happen much sooner after it's timer had expired. It now will be done as soon as it expires instead of the second or third update update after it had expired.
3. Changed some of the text messages in the Event Log dealing with the Stationary Zone for consistency.
4. Restart - When HA & iCloud3 restarts, the Stationary Zones do not exist yet. However, a device's Restore State data used during a restart will have Stationary Zone information (names, travel directioys, current status) in it's restore sensor values until the initial locate is done. The device's sensors would be set to a Station Zone incorrectly. This has been fixed.
4. Sensor tweaks:
1. `_arrival_time` - Changed the icon to better show when the device was in the zone (house/map icon solid = arrived) or when you will arrive (house/map icon not solid = calculated arrival time).
2. `_zone_distance` & `_home_distance` - Changed the icon to show if you are going towards Home, away from Home or at Home.
3. `_battery` - Added the iOS App battery sensors entity names that are monitored to the sensor attributes.
5. Waze times and distances are now available when less than 2-minutes from home or a tracked-from zone.
6. Monitored Devices - The iOS App battery and location information was not displayed for monitored devices. This has been fixed.
7. Event Log - The iCloud3 and Event Log versions are displayed when you hover over Actions. Also made some other formatting changes.
8. Other internal changes.

---> A BROWSER REFRESH WILL BE REQUESTED <---

Expand All @@ -13,8 +33,8 @@ Beta 19.1 - 7/10/2023
...................
1. Bug Fix - Fixed a problem that may be encountered if you have a watch paired to an iPhone and are tracking the iPhone but not the watch.
2. New Sensors:
1. `[devicename]_travel_time_hhmm` - Displays the travel time to the zone in an hh:mm format.
2. `[devicename]_arrival_time` - The expected arrival time to the zone (current time + travel time) (5:25p, 17:25) or the time you arrived in the Home or other Tracked From zone (@5:25p, @17:25)
1. `_travel_time_hhmm` - Displays the travel time to the zone in an hh:mm format.
2. `_arrival_time` - The expected arrival time to the zone (current time + travel time) (5:25p, 17:25) or the time you arrived in the Home or other Tracked From zone (@5:25p, @17:25)
3. Simplified the sensors associated with track_from_zones other than Home.


Expand Down
14 changes: 9 additions & 5 deletions custom_components/icloud3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import logging

from .const import (DOMAIN, PLATFORMS, MODE_PLATFORM, MODE_INTEGRATION, CONF_VERSION,
CONF_SETUP_ICLOUD_SESSION_EARLY,
CONF_SETUP_ICLOUD_SESSION_EARLY, CONF_EVLOG_BTNCONFIG_URL,
SENSOR_EVENT_LOG_NAME, SENSOR_WAZEHIST_TRACK_NAME,
EVLOG_IC3_STARTING, VERSION, )

Expand Down Expand Up @@ -123,17 +123,21 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
Gb.operating_mode = MODE_INTEGRATION
await async_get_ha_location_info(hass)

recorder_prefilter.add_filter(hass, [SENSOR_EVENT_LOG_NAME, SENSOR_WAZEHIST_TRACK_NAME])
Gb.PyiCloud = None
Gb.EvLog = event_log.EventLog(Gb.hass)
Gb.start_icloud3_inprocess_flag = True
Gb.PyiCloud = None

recorder_prefilter.add_filter(hass, [SENSOR_EVENT_LOG_NAME, SENSOR_WAZEHIST_TRACK_NAME])
start_ic3.initialize_directory_filenames()
config_file.load_storage_icloud3_configuration_file()
start_ic3.set_log_level(Gb.log_level)
open_ic3_log_file(new_log_file=Gb.log_debug_flag)

Gb.evlog_btnconfig_url = Gb.conf_profile[CONF_EVLOG_BTNCONFIG_URL].strip()
Gb.evlog_version = Gb.conf_profile['event_log_version']
Gb.EvLog = event_log.EventLog(Gb.hass)
log_info_msg(f"Setting up iCloud3 {VERSION} - Using Integration method")

Gb.start_icloud3_inprocess_flag = True

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
try:
# _traceha(f"hass.data=")
Expand Down
56 changes: 36 additions & 20 deletions custom_components/icloud3/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
TRACK_DEVICE, MONITOR_DEVICE, INACTIVE_DEVICE,
NAME, FRIENDLY_NAME, FNAME, TITLE, BATTERY,
ZONE, HOME_DISTANCE, WAZE_SERVERS_FNAME,
CONF_VERSION, CONF_EVLOG_CARD_DIRECTORY, CONF_HA_CONFIG_IC3_URL,
CONF_VERSION, CONF_EVLOG_CARD_DIRECTORY,
CONF_EVLOG_BTNCONFIG_URL,
CONF_USERNAME, CONF_PASSWORD, CONF_DEVICES, CONF_SETUP_ICLOUD_SESSION_EARLY,
CONF_DATA_SOURCE, CONF_VERIFICATION_CODE,
CONF_TRACK_FROM_ZONES, CONF_TRACK_FROM_BASE_ZONE, CONF_TRACK_FROM_HOME_ZONE,
Expand All @@ -38,7 +39,7 @@
CONF_GPS_ACCURACY_THRESHOLD, CONF_OLD_LOCATION_THRESHOLD, CONF_OLD_LOCATION_ADJUSTMENT,
CONF_TRAVEL_TIME_FACTOR, CONF_TFZ_TRACKING_MAX_DISTANCE,
CONF_PASSTHRU_ZONE_TIME, CONF_LOG_LEVEL,
CONF_DISPLAY_ZONE_FORMAT, CONF_DISPLAY_GPS_LAT_LONG,
CONF_DISPLAY_ZONE_FORMAT, CONF_DEVICE_TRACKER_STATE_SOURCE, CONF_DISPLAY_GPS_LAT_LONG,
CONF_CENTER_IN_ZONE, CONF_DISCARD_POOR_GPS_INZONE,
CONF_DISTANCE_BETWEEN_DEVICES,
CONF_WAZE_USED, CONF_WAZE_SERVER, CONF_WAZE_MAX_DISTANCE, CONF_WAZE_MIN_DISTANCE,
Expand Down Expand Up @@ -294,11 +295,16 @@ def dict_value_to_list(key_value_dict):
}
DISPLAY_ZONE_FORMAT_ITEMS_KEY_TEXT = {}
DISPLAY_ZONE_FORMAT_ITEMS_KEY_TEXT_BASE = {
'fname': 'HA Zone Friendly Name, (Home, Away, TheShores)',
'fname': 'HA Zone Friendly Name (Home, Away, TheShores) →→→ PREFERRED',
'zone': 'HA Zone entity_id (home, not_home, the_shores)',
'name': 'iCloud3 reformated Zone entity_id (zone.the_shores → TheShores)',
'title': 'iCloud3 reformated Zone entity_id (zone.the_shores → The Shores)'
}
DEVICE_TRACKER_STATE_SOURCE_ITEMS_KEY_TEXT = {
'ic3_fname': 'iCloud3 Determines the Zone - Set to Zone Friendly Name (gps & accuracy)',
'ic3_evlog': 'iCloud3 Determines the Zone - Set to EvLog Zone Display Name (gps & accuracy)',
'ha_gps': 'HA Determines the Zone - Based on gps coordinates (except Stationary Zones)'
}
LOG_LEVEL_ITEMS_KEY_TEXT = {
'info': 'Info - Log General Information',
'debug': 'Debug - Log Internal Tracking Monitors',
Expand Down Expand Up @@ -665,18 +671,15 @@ def initialize_options(self):
# in case the username/password is changed and another account is accessed. These will not
# intefer with ones already in use by iC3. The Global Gb variables will be set to the local
# variables if they were changes and a iC3 Restart was selected when finishing the config setup.

self.PyiCloud = None
self.username = None
self.password = None
if Gb.PyiCloud: self.PyiCloud = Gb.PyiCloud
self.username = Gb.username or Gb.conf_tracking[CONF_USERNAME]
self.password = Gb.password or Gb.conf_tracking[CONF_PASSWORD]
self.obscure_username = ''
self.obscure_password = ''
self.show_username_password = False

if Gb.PyiCloud:
self.PyiCloud = Gb.PyiCloud
self.username = Gb.username
self.password = Gb.password

# Variables used for device selection and update on the device_list and device_update forms
self.form_devices_list_all = [] # List of the devices in the Gb.conf_tracking[DEVICES] parameter
self.form_devices_list_displayed = [] # List of the devices displayed on the device_list form
Expand Down Expand Up @@ -982,7 +985,7 @@ def common_form_handler(self, user_input=None, action_item=None, errors=None):

log_debug_msg(f"{self.step_id} ({action_item}) > UserInput-{user_input}, Errors-{errors}")

post_event(f"Configuration Updated > Type-{self.step_id.replace('_', ' ').title()}")
post_event(f"Configuration Changed > Type-{self.step_id.replace('_', ' ').title()}")
self._update_configuration_file(user_input)

# Redisplay the menu if there were no errors
Expand Down Expand Up @@ -1528,22 +1531,25 @@ def _validate_format_settings(self, user_input):
The display_zone_format may contain '(Example: ...). If so, strip it off.
'''
user_input = self._option_text_to_parm(user_input, CONF_DISPLAY_ZONE_FORMAT, DISPLAY_ZONE_FORMAT_ITEMS_KEY_TEXT)
user_input = self._option_text_to_parm(user_input, CONF_DEVICE_TRACKER_STATE_SOURCE, DEVICE_TRACKER_STATE_SOURCE_ITEMS_KEY_TEXT)
user_input = self._option_text_to_parm(user_input, CONF_UNIT_OF_MEASUREMENT, UNIT_OF_MEASUREMENT_ITEMS_KEY_TEXT)
user_input = self._option_text_to_parm(user_input, CONF_TIME_FORMAT, TIME_FORMAT_ITEMS_KEY_TEXT)
user_input = self._option_text_to_parm(user_input, CONF_LOG_LEVEL, LOG_LEVEL_ITEMS_KEY_TEXT)
user_input = self._strip_special_text_from_user_input(user_input)

if Gb.display_zone_format != user_input[CONF_DISPLAY_ZONE_FORMAT]:
if (Gb.display_zone_format != user_input[CONF_DISPLAY_ZONE_FORMAT]):
# or Gb.device_tracker_state_source != user_input[CONF_DEVICE_TRACKER_STATE_SOURCE]):
self.config_flow_updated_parms.update(['zone_formats'])

return user_input

#-------------------------------------------------------------------------------------------
def _validate_tracking_parameters(self, user_input):
'''
The display_zone_format may contain '(Example: ...). If so, strip it off.
Update the profile parameters
'''
user_input[CONF_HA_CONFIG_IC3_URL] = user_input[CONF_HA_CONFIG_IC3_URL].strip()
user_input[CONF_EVLOG_BTNCONFIG_URL] = user_input[CONF_EVLOG_BTNCONFIG_URL].strip()

return user_input

#-------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1792,6 +1798,12 @@ async def async_step_icloud_account(self, user_input=None, errors=None):
or user_input[CONF_PASSWORD] != Gb.conf_tracking[CONF_PASSWORD])):
await self._log_into_icloud_account(user_input, called_from_step_id='icloud_account')

if action_item == 'save' and self.PyiCloud != Gb.PyiCloud:
Gb.PyiCloud = Gb.PyiCloudInit = self.PyiCloud
Gb.username = self.username
Gb.password = self.password


if (self.PyiCloud and self.PyiCloud.requires_2fa):
errors = {'base': 'verification_code_needed'}
return await self.async_step_reauth(user_input=None,
Expand Down Expand Up @@ -1892,7 +1904,7 @@ async def async_step_reauth(self, user_input=None, errors=None, called_from_step
post_event( f"{EVLOG_NOTICE}The Verification Code was accepted ({user_input[CONF_VERIFICATION_CODE]})")
post_event(f"{EVLOG_NOTICE}iCLOUD ALERT > Apple ID Verification complete")

clear_alert()
Gb.EvLog.clear_alert()
Gb.force_icloud_update_flag = True
PyiCloud.new_2fa_code_already_requested_flag = False

Expand Down Expand Up @@ -2213,7 +2225,7 @@ def _delete_this_device(self):
""" Delete the device_tracker entity and associated ic3 configuration """

devicename = self.conf_device_selected[CONF_IC3_DEVICENAME]
event_msg = (f"Configuration Updated > DeleteDevice-{devicename}, "
event_msg = (f"Configuration Changed > DeleteDevice-{devicename}, "
f"{self.conf_device_selected[CONF_FNAME]}/"
f"{DEVICE_TYPE_FNAME[self.conf_device_selected[CONF_DEVICE_TYPE]]}")
post_event(event_msg)
Expand Down Expand Up @@ -2372,12 +2384,12 @@ async def async_step_update_device(self, user_input=None, errors=None):
self.device_list_page_selected_idx[self.device_list_page_no] = \
self.conf_device_selected_idx

event_msg = (f"Configuration Updated > AddDevice-{ui_devicename}, "
event_msg = (f"Configuration Changed > AddDevice-{ui_devicename}, "
f"{self.conf_device_selected[CONF_FNAME]}/"
f"{DEVICE_TYPE_FNAME[self.conf_device_selected[CONF_DEVICE_TYPE]]}")
post_event(event_msg)
else:
event_msg = (f"Configuration Updated > ChangeDevice-{ui_devicename}, "
event_msg = (f"Configuration Changed > ChangeDevice-{ui_devicename}, "
f"{self.conf_device_selected[CONF_FNAME]}/"
f"{DEVICE_TYPE_FNAME[self.conf_device_selected[CONF_DEVICE_TYPE]]}")
post_event(event_msg)
Expand Down Expand Up @@ -3941,6 +3953,10 @@ def form_schema(self, step_id):
default=self._option_parm_to_text(CONF_DISPLAY_ZONE_FORMAT, DISPLAY_ZONE_FORMAT_ITEMS_KEY_TEXT)):
selector.SelectSelector(selector.SelectSelectorConfig(
options=dict_value_to_list(DISPLAY_ZONE_FORMAT_ITEMS_KEY_TEXT), mode='dropdown')),
vol.Required(CONF_DEVICE_TRACKER_STATE_SOURCE,
default=self._option_parm_to_text(CONF_DEVICE_TRACKER_STATE_SOURCE, DEVICE_TRACKER_STATE_SOURCE_ITEMS_KEY_TEXT)):
selector.SelectSelector(selector.SelectSelectorConfig(
options=dict_value_to_list(DEVICE_TRACKER_STATE_SOURCE_ITEMS_KEY_TEXT), mode='dropdown')),
vol.Required(CONF_UNIT_OF_MEASUREMENT,
default=self._option_parm_to_text(CONF_UNIT_OF_MEASUREMENT, UNIT_OF_MEASUREMENT_ITEMS_KEY_TEXT)):
selector.SelectSelector(selector.SelectSelectorConfig(
Expand Down Expand Up @@ -4083,8 +4099,8 @@ def form_schema(self, step_id):
default=self._parm_or_error_msg(CONF_EVLOG_CARD_DIRECTORY, conf_group=CF_PROFILE)):
selector.SelectSelector(selector.SelectSelectorConfig(
options=dict_value_to_list(self.opt_www_directory_list), mode='dropdown')),
vol.Optional(CONF_HA_CONFIG_IC3_URL,
default=self._parm_or_error_msg(CONF_HA_CONFIG_IC3_URL, conf_group=CF_PROFILE)):
vol.Optional(CONF_EVLOG_BTNCONFIG_URL,
default=f"{self._parm_or_error_msg(CONF_EVLOG_BTNCONFIG_URL, conf_group=CF_PROFILE)} "):
selector.TextSelector(),

vol.Required('action_items',
Expand Down
Loading

0 comments on commit 055f541

Please sign in to comment.