Skip to content

Commit

Permalink
iCloud3 v3.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gcobb321 committed Mar 30, 2024
1 parent 040c626 commit cf5eb99
Show file tree
Hide file tree
Showing 21 changed files with 445 additions and 269 deletions.
15 changes: 15 additions & 0 deletions custom_components/icloud3/ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
### Important Links:
- iCloud3 Documentation is [here](https://gcobb321.github.io/icloud3_v3_docs/#/chapters/0.1-introduction)
- The *Installing iCloud3* chapter describes migrating from iCloud3 v2 and installing iCloud3 for the first time

### Change Log
v3.0.2 - 3/30/2023
.......................
1. ICLOUD SERVER ERROR MESSAGE (Fixed) - When the iCloud servers did not respond with location information, the 'no response from iCloud servers' error was displayed correctly. This was followed by another unrelated error which should have not been displayed.
2. ALERTS, STARTUP ERRORS, WARNING MESSAGES (New) - Unusual errors or warning events for iPhones, iPads, and Watches are displayed in a green bar on the first line of the Event Log whenthe event occurs. The message will continue displaying until the event is corrected. This includes (1) startup errors, (2) no data received from iCloud Location Servers, (3) when a device is offline and (4) when a device's location is over 5-hours old and (5) when tracking is paused. The messages from AirPods and iPods are only displayed when their Event Log screen is displayed.
3. OTHER - Minor code corrections and cleanup.

v3.0.1.1 - 3/24/2024
.......................
1. ICLOUD-0.LOG FILE (Fixed) - The icloud-0.log file was not being created when the HA 'logger:' statement was not in the HA configuration.yaml file.

v3.0.1 - 3/20/2024
.......................
1. UPDATE SENSOR & DEVICE TRACKER ENTITIES (Improvement) - Changed the method of updating these items at the request of @balloob (Paulus Schousten, HA Founder) to prevent a potential Home Assistant lockup when doing an update.
Expand Down
2 changes: 1 addition & 1 deletion custom_components/icloud3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from .global_variables import GlobalVariables as Gb
from .helpers.messaging import (_trace, _traceha, open_ic3log_file_init,
post_alert, post_startup_alert,
post_evlog_greenbar_msg, post_startup_alert,
log_info_msg, log_debug_msg, log_error_msg,
log_exception_HA, log_exception)
from .helpers.time_util import (time_now_secs, )
Expand Down
4 changes: 2 additions & 2 deletions custom_components/icloud3/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ async def async_step_reauth(self, user_input=None, errors=None):
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")

Gb.EvLog.clear_alert()
Gb.EvLog.clear_evlog_greenbar_msg()
Gb.EvLog.update_event_log_display("")
start_ic3.set_primary_data_source(FAMSHR)
Gb.PyiCloud.new_2fa_code_already_requested_flag = False
Expand Down Expand Up @@ -2351,7 +2351,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")

Gb.EvLog.clear_alert()
Gb.EvLog.clear_evlog_greenbar_msg()
Gb.icloud_force_update_flag = True
PyiCloud.new_2fa_code_already_requested_flag = False

Expand Down
2 changes: 1 addition & 1 deletion custom_components/icloud3/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

VERSION = '3.0.1.1'
VERSION = '3.0.2'
#-----------------------------------------
DOMAIN = 'icloud3'
ICLOUD3 = 'iCloud3'
Expand Down
33 changes: 22 additions & 11 deletions custom_components/icloud3/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

from .helpers.common import (instr, is_zone, isnot_zone, is_statzone, list_add, list_del,
circle_letter, format_gps, zone_dname, )
from .helpers.messaging import (post_event, post_error_msg, post_monitor_msg, post_alert, clear_alert,
from .helpers.messaging import (post_event, post_error_msg, post_monitor_msg, post_evlog_greenbar_msg, clear_evlog_greenbar_msg,
log_exception, log_debug_msg, log_error_msg,
post_startup_alert,
post_internal_error, _trace, _traceha, )
Expand Down Expand Up @@ -1018,12 +1018,17 @@ def is_online(self):

@property
def is_offline(self):
''' Returns True/False if the device is offline based on the device_status '''
'''
Returns True/False if the device is offline based on the device_status
Return False if there is no GPS location so the old location will be processed
'''
if self.no_location_data:
return False

if (self.dev_data_device_status not in DEVICE_STATUS_OFFLINE
or self.is_data_source_FMF):
# clear_alert()
return False
# post_alert(f"{self.fname} is Offline")

return True

@property
Expand Down Expand Up @@ -1069,12 +1074,16 @@ def is_tracking_from_home(self):

#--------------------------------------------------------------------
def update_location_gps_accuracy_status(self):
if self.icloud_devdata_useable_flag or self.loc_data_secs == 0:
self.loc_data_isold = False
if self.no_location_data or self.is_offline:
self.loc_data_isold = True
self.loc_data_ispoorgps = False
self.icloud_devdata_useable_flag = False
elif self.icloud_devdata_useable_flag or self.loc_data_secs == 0:
self.loc_data_isold = False
self.loc_data_ispoorgps = False
else:
self.loc_data_isold = (secs_since(self.loc_data_secs) > self.old_loc_threshold_secs + 5
or self.is_offline)
self.loc_data_isold = (secs_since(self.loc_data_secs) > self.old_loc_threshold_secs + 5
or self.is_offline)
self.loc_data_ispoorgps = (self.loc_data_gps_accuracy > Gb.gps_accuracy_threshold)
self.icloud_devdata_useable_flag = (self.loc_data_isold is False
and self.loc_data_ispoorgps is False)
Expand Down Expand Up @@ -2013,8 +2022,10 @@ def update_dev_loc_data_from_raw_data_FAMSHR_FMF(self, RawData, requesting_devic
self.dev_data_low_power_mode = RawData.device_data.get(ICLOUD_LOW_POWER_MODE, "")

if RawData.device_data.get(ICLOUD_BATTERY_LEVEL):
icloud_rawdata_battery_level = round(RawData.device_data.get(ICLOUD_BATTERY_LEVEL, 0) * 100)
icloud_rawdata_battery_status = RawData.device_data.get(ICLOUD_BATTERY_STATUS, UNKNOWN)
# icloud_rawdata_battery_level = round(RawData.device_data.get(ICLOUD_BATTERY_LEVEL, 0) * 100)
# icloud_rawdata_battery_status = RawData.device_data.get(ICLOUD_BATTERY_STATUS, UNKNOWN)
icloud_rawdata_battery_level = RawData.battery_level
icloud_rawdata_battery_status = RawData.battery_status
else:
icloud_rawdata_battery_level = 0
icloud_rawdata_battery_status = UNKNOWN
Expand Down Expand Up @@ -2315,7 +2326,7 @@ def format_info_msg(self):

if self.NearDeviceUsed:
info_msg +=(f"UsedNearbyDevice-{self.NearDeviceUsed.fname}, "
f"({m_to_um_ft(Device.near_device_distance, as_integer=True)}")
f"({m_to_um_ft(self.near_device_distance, as_integer=True)}")

# if self.data_source != self.dev_data_source.lower():
#info_msg += f"LocationData-{self.dev_data_source}, "
Expand Down
2 changes: 1 addition & 1 deletion custom_components/icloud3/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers import (entity_registry as er, device_registry as dr, )
from homeassistant.helpers import (entity_registry as er, device_registry as dr, area_registry as ar)
from homeassistant.const import (CONF_DEVICE_ID, CONF_DOMAIN, CONF_ENTITY_ID, CONF_EVENT,
CONF_PLATFORM, CONF_TYPE, CONF_ZONE, )

Expand Down
137 changes: 94 additions & 43 deletions custom_components/icloud3/helpers/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,40 @@
'items', 'userInfo', 'prsId', 'dsid', 'dsInfo', 'webservices', 'locations',
'devices', 'content', 'followers', 'following', 'contactDetails', ]

TABS_10 = "\t\t\t\t\t\t\t\t\t\t"
TABS_BOX_DEBUG = f"{'\t'*10} "
TABS_BOX_INFO = f"{'\t'*5} "
TABS_BOX_EVLOG_EXPORT = f"{'\t'*3}"
TABS_8 = "\t\t\t\t\t\t\t\t"
TABS_9 = "\t\t\t\t\t\t\t\t\t"
TABS_3 = "\t\t\t"
TABS_2 = "\t\t"
# TABS_BOX_DEBUG = "\t\t\t\t\t\t\t\t\t\t "
# TABS_BOX_INFO = "\t\t\t\t\t "
# TABS_BOX_EVLOG_EXPORT = "\t\t\t"
SP50 = ' '*50
SP = {
4: SP50[1:4],
5: SP50[1:5],
6: SP50[1:6],
8: SP50[1:8],
10: SP50[1:10],
12: SP50[1:12],
16: SP50[1:16],
22: SP50[1:22],
28: SP50[1:28],
26: SP50[1:26],
44: SP50[1:44],
48: SP50[1:48],
50: SP50,
}
# SP = {
# 4: ' '*4,
# 5: ' '*5,
# 6: ' '*6,
# 8: ' '*8,
# 10: ' '*10,
# 12: ' '*12,
# 16: ' '*16,
# 22: ' '*22,
# 28: ' '*28,
# 26: ' '*26,
# 44: ' '*44,
# 48: ' '*48,
# 50: ' '*50,
# }

#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#
Expand Down Expand Up @@ -184,20 +210,39 @@ def refresh_event_log(devicename='', show_one_screen=False):
Gb.EvLog.update_event_log_display(devicename='', show_one_screen=False)

#-------------------------------------------------------------------------------------------
def post_alert(alert_message):
def post_evlog_greenbar_msg(Device, evlog_greenbar_msg='+'):
'''
Post an Alert Message on the first line of the event log items
Input:
Device:
If specified, display msg on this Device's EvLog screen only
If not specified, display on all screens
evlog_greenbar_msg:
Message to display -
'''
# See if the message is really in the Device parameter
if evlog_greenbar_msg == '+':
evlog_greenbar_msg = Device

if alert_message == '':
Gb.EvLog.clear_alert()
# Device was specified, check to see if this is the screen displayed
else:
Gb.EvLog.alert_message = alert_message
Gb.EvLog.display_user_message('')
fname = Device.fname if Device.is_tracked else f"{Device.fname} 🅜"
if Gb.EvLog.evlog_attrs["fname"] != fname:
return

if Gb.EvLog.greenbar_alert_msg == evlog_greenbar_msg:
return

if evlog_greenbar_msg == '':
Gb.EvLog.clear_evlog_greenbar_msg()
else:
Gb.EvLog.greenbar_alert_msg = evlog_greenbar_msg
Gb.EvLog.display_user_message('')

#-------------------------------------------------------------------------------------------
def clear_alert():
Gb.EvLog.clear_alert()
def clear_evlog_greenbar_msg():
Gb.EvLog.clear_evlog_greenbar_msg()
Gb.EvLog.display_user_message('')

#--------------------------------------------------------------------
Expand Down Expand Up @@ -307,7 +352,7 @@ def check_ic3log_file_exists(ic3logger_file):
open_ic3log_file(new_log_file=True)

log_msg = f"{EVLOG_IC3_STARTING}Recreated iCloud3 Log File: {ic3logger_file}"
log_msg = f" {format_startup_header_box(log_msg)}"
log_msg = f"{format_startup_header_box(log_msg)}"
log_msg = f"{format_header_box_indent(log_msg, 4).replace('⡇', '⛔')}"
Gb.iC3Logger.info(log_msg)

Expand Down Expand Up @@ -357,29 +402,30 @@ def write_config_file_to_ic3log():
conf_tracking_recd[CONF_DEVICES] = f"{len(Gb.conf_devices)}"

Gb.trace_prefix = '_INIT_'
tabs = TABS_BOX_DEBUG if Gb.log_debug_flag else \
TABS_BOX_INFO
indent = SP[44] if Gb.log_debug_flag else SP[26]
log_msg = ( f"iCloud3 v{Gb.version}, "
f"{dt_util.now().strftime('%A')}, "
f"{dt_util.now().strftime(DATETIME_FORMAT)[:19]}")
log_msg = ( f" \n"
f"{tabs}\t\t{DASH_50}\n"
f"{tabs}\t\t{log_msg}\n"
f"{tabs}\t\t{DASH_50}")
f"{indent}{DASH_50}\n"
f"{indent}{log_msg}\n"
f"{indent}{DASH_50}")

Gb.iC3Logger.info(log_msg)

# Write the ic3 configuration (general & devices) to the Log file
log_info_msg(f"Profile:\n{tabs}\t\t{Gb.conf_profile}")
log_info_msg(f"Tracking:\n{tabs}\t\t{conf_tracking_recd}")

log_info_msg(f"General Configuration:\n{tabs}\t\t{Gb.conf_general}")
log_info_msg(f"{tabs}\t\t{Gb.ha_location_info}")
log_info_msg(f"Profile:\n"
f"{indent}{Gb.conf_profile}")
log_info_msg(f"Tracking:\n"
f"{indent}{conf_tracking_recd}")
log_info_msg(f"General Configuration:\n"
f"{indent}{Gb.conf_general}\n"
f"{indent}{Gb.ha_location_info}")
log_info_msg("")

for conf_device in Gb.conf_devices:
log_info_msg( f"{conf_device[CONF_FNAME]}, {conf_device[CONF_IC3_DEVICENAME]}:\n"
f"{tabs}\t\t{conf_device}")
f"{indent}{conf_device}")
log_info_msg("")

#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Expand Down Expand Up @@ -409,7 +455,7 @@ def log_info_msg(module_name, log_msg='+'):
log_msg = format_msg_line(log_msg)
write_ic3log_recd(log_msg)

log_msg = log_msg.replace(' > +', ' > ...\n\t\t\t\t\t\t\t\t\t\t\t+')
log_msg = log_msg.replace(' > +', f" > ...\n{SP[22]}+")
Gb.HALogger.debug(log_msg)

#--------------------------------------------------------------------
Expand Down Expand Up @@ -453,7 +499,7 @@ def log_debug_msg(devicename_or_Device, log_msg='+', msg_prefix=None):
write_ic3log_recd(log_msg)


log_msg = log_msg.replace(' > +', ' > ...\n\t\t\t\t\t\t\t\t\t\t\t+')
log_msg = log_msg.replace(' > +', f" > ...\n{SP[22]}+")
Gb.HALogger.debug(log_msg)

#--------------------------------------------------------------------
Expand Down Expand Up @@ -508,7 +554,9 @@ def format_msg_line(log_msg, area=None):
log_msg = format_header_box_indent(log_msg, len(source))
msg_prefix= ' ' if log_msg.startswith('⡇') else \
' ⡇ ' if Gb.trace_group else \
' > '
' '
# ' ▹ '
# ' > '

log_msg = filter_special_chars(log_msg)
log_msg = f"{source}{msg_prefix}{log_msg}"
Expand All @@ -524,9 +572,9 @@ def filter_special_chars(recd, evlog_export=False):
Filter out EVLOG_XXX control fields
'''

tabs = TABS_BOX_EVLOG_EXPORT if evlog_export else \
TABS_BOX_DEBUG if Gb.log_debug_flag else \
TABS_BOX_INFO
indent =SP[16] if evlog_export else \
SP[48] if Gb.log_debug_flag else \
SP[28]
if recd.startswith('^'): recd = recd[3:]

recd = recd.replace(EVLOG_MONITOR, '')
Expand All @@ -537,8 +585,8 @@ def filter_special_chars(recd, evlog_export=False):
recd = recd.replace(NBSP5, ' ')
recd = recd.replace(NBSP6, ' ')
recd = recd.strip()
recd = recd.replace(CRLF, f"\n{tabs}\t ")
recd = recd.replace('◦', f"\t◦")
recd = recd.replace(CRLF, f"\n{indent}")
recd = recd.replace('◦', f" ◦")
recd = recd.replace('* >', '')
recd = recd.replace('&lt;', '<')

Expand Down Expand Up @@ -588,22 +636,25 @@ def format_header_box(recd, start_finish=None, evlog_export=False):

top_char = bot_char = DASH_50
if start_finish == 'start':
bot_char = f"{''*37}"
bot_char = f"{''*37}"
Gb.trace_group = True
elif start_finish == 'finish':
top_char = f"{'⠐'*37}"
top_char = f"{'⠂'*37}"
# top_char = f"{'⠐'*37}"
Gb.trace_group = False

# return (f"⡇{top_char}\n"
return (f"⡇{top_char}\n"
f">⡇\t\t{recd[start_pos:].upper()}\n"
f">⡇{bot_char}")
f"▹⡇{SP[4]}{recd[start_pos:].upper()}\n"
f"▹⡇{bot_char}")
# f"▹⡇{bot_char}")

#--------------------------------------------------------------------
def format_header_box_indent(log_msg, indent):
if instr(log_msg, '>⡇') is False:
if instr(log_msg, '⡇') is False:
return log_msg

return log_msg.replace('>⡇', f"{' '*(16+indent)}")
return log_msg.replace('', f"{' '*(16+indent)}")

#-------------------------------------------------------------------------------------------
def _resolve_devicename_log_msg(devicename_or_Device, event_msg):
Expand Down Expand Up @@ -872,7 +923,7 @@ def _trace(devicename_or_Device, items='+'):
#rc9 Reworked post_event and write_config_file to call modules directly
if Gb.EvLog:
Gb.EvLog.post_event(devicename, f"^3^{called_from} {items}")
write_ic3log_recd(f"{called_from} ⛔━⛔ {items}")
write_ic3log_recd(f"{called_from}⛔.⛔ . . . {devicename} > {items}")

#--------------------------------------------------------------------
def _traceha(items, v1='+++', v2='', v3='', v4='', v5=''):
Expand All @@ -886,7 +937,7 @@ def _traceha(items, v1='+++', v2='', v3='', v4='', v5=''):
else:
trace_msg = (f"|{v1}|-|{v2}|-|{v3}|-|{v4}|-|{v5}|")

trace_msg = (f"{called_from} ⛔━⛔ {items} {trace_msg}")
trace_msg = (f"{called_from}⛔.⛔ . . . {items} {trace_msg}")

write_ic3log_recd(trace_msg)

Expand Down
Loading

0 comments on commit cf5eb99

Please sign in to comment.