Skip to content

Commit

Permalink
iCloud3 v3, Prerelease 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
gcobb321 committed Aug 24, 2023
1 parent 91bb933 commit 8add1d3
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 35 deletions.
9 changes: 9 additions & 0 deletions custom_components/icloud3/ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
patch pr1.2 - Prerelease 1.2- 8/23/2023
...............................
1. Battery - Fixed a problem where the battery level/status was not being updated immediately in the Event Log when it went from 'charging' to 'not charging' or 'not charging' to 'charging'.
2. GPS - The 'Show GPS Coordinates' parameter is now applied when the event is displayed in the Event Log instead of when it is added to the Event Log. You can disable this parameter so they are not normally displayed. Later, if you need to review where a device has been, reenable the parameter and the location coordinates for previous events will be displayed.
3. Event Log - Fixed a problem where the event time was not displayed if the 'Zone Display-as' parameter was set to display the zone entity_id.
4. Event Log - Fixed a problem with the Event Log Card not detecting a version update.

pr1.1 - Prerelease 1.2- 8/220/2023
...............................
rc2 - Release Candidate 3 - 8/14/2023
...............................
1. Reverted the 'manifest.json' file to prevent iCloud3 from hanging on an HA startup if there is a problem starting some of the HA components.
Expand Down
7 changes: 7 additions & 0 deletions custom_components/icloud3/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,9 @@ async def async_step_device_list(self, user_input=None, errors=None):
self._prepare_device_selection_list()
self.sensor_entity_attrs_changed = {}

if Gb.async_add_entities_device_tracker is None:
self.errors='no_add_entities_device_tracker_fct'

self.step_id = 'device_list'

return self.async_show_form(step_id=self.step_id,
Expand Down Expand Up @@ -2446,12 +2449,16 @@ async def async_step_add_device(self, user_input=None, errors=None):
self.errors = errors or {}
self.errors_user_input = {}

if Gb.async_add_entities_device_tracker is None:
return await self.async_step_device_list(errors='no_add_entities_device_tracker_fct')

if user_input is None:
return self.async_show_form(step_id=self.step_id,
data_schema=self.form_schema(self.step_id),
errors=self.errors)

user_input, action_item = self._action_text_to_item(user_input)
user_input = self._strip_special_text_from_user_input(user_input, CONF_IC3_DEVICENAME)
user_input = self._option_text_to_parm(user_input, CONF_TRACKING_MODE, TRACKING_MODE_ITEMS_KEY_TEXT)
user_input = self._option_text_to_parm(user_input, CONF_DEVICE_TYPE, DEVICE_TYPE_FNAME)
log_debug_msg(f"{self.step_id} ({action_item}) > UserInput-{user_input}, Errors-{errors}")
Expand Down
5 changes: 2 additions & 3 deletions custom_components/icloud3/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

VERSION = '3.0pr1'
VERSION = '3.0pr1.3'

DOMAIN = 'icloud3'
ICLOUD3 = 'iCloud3'
Expand Down Expand Up @@ -360,8 +360,7 @@
'notcharging': 'not charging',
'not charging': 'not charging',
'not_charging': 'not charging',
'unknown': 'unknown',
'': 'unknown',
'unknown': '',
}
BATTERY_STATUS_FNAME = {
# 'full, full': 'Full, Not Charging',
Expand Down
33 changes: 20 additions & 13 deletions custom_components/icloud3/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,8 @@ def update_battery_data_from_iosapp(self):
if STATE not in battery_level_attrs:
return False

battery_status = entity_io.get_state(self.iosapp_entity[BATTERY_STATUS])
#battery_status_old = entity_io.get_state(self.iosapp_entity[BATTERY_STATUS])
battery_status = 'charging' if instr(battery_level_attrs['icon'], 'charging') else 'not charging'
battery_level = int(battery_level_attrs[STATE])
battery_update_secs = battery_level_attrs[LAST_CHANGED_SECS]

Expand Down Expand Up @@ -1648,23 +1649,29 @@ def _update_battery_data_fields(self, battery_level, battery_status, battery_upd
Update the dev_data_battery and iosapp_battery fields with the battery data if this
data is newer
'''
if (battery_level < 1 or battery_status == ''
or battery_update_secs <= self.dev_data_battery_update_secs):

if battery_level < 1 or battery_status == '':
return
elif battery_status != self.dev_data_battery_status:
pass
elif battery_update_secs <= self.dev_data_battery_update_secs:
return

if battery_level == 100 and self.PyiCloud_RawData_famshr:
famshr_battery_status = self.PyiCloud_RawData_famshr.device_data[ICLOUD_BATTERY_STATUS]
battery_status = f"full, {famshr_battery_status}"
if battery_level == 100 and data_source == FAMSHR_FNAME and self.PyiCloud_RawData_famshr:
battery_status = self.PyiCloud_RawData_famshr.device_data[ICLOUD_BATTERY_STATUS]
#famshr_battery_status = self.PyiCloud_RawData_famshr.device_data[ICLOUD_BATTERY_STATUS]
#battery_status = f"full, {famshr_battery_status}"

if (battery_update_secs > self.dev_data_battery_update_secs
or battery_status != self.dev_data_battery_status):
self.dev_data_battery_source = data_source
self.dev_data_battery_level = self.iosapp_data_battery_level = battery_level
self.dev_data_battery_status = self.iosapp_data_battery_status = battery_status if battery_status else UNKNOWN
if battery_status:
self.dev_data_battery_status = self.iosapp_data_battery_status = battery_status
self.dev_data_battery_update_secs = self.iosapp_data_battery_update_secs = battery_update_secs

#-------------------------------------------------------------------
def display_battery_info_msg(self, display_msg=False):
def display_battery_info_msg(self, force_display=False):
'''
Display the Battery info msg if the status (Charging, Not Charging) has changed or the
battery level is divisible by 5 (80, 85, etc.)
Expand All @@ -1673,16 +1680,16 @@ def display_battery_info_msg(self, display_msg=False):
if self.dev_data_battery_level < 1:
return False

last_battery_msg_level_status = self.last_battery_msg.split(', ')
if (last_battery_msg_level_status[1] != self.format_battery_status
or display_msg):
last_battery_level, last_battery_status = self.last_battery_msg.split('%, ')

if last_battery_status != self.format_battery_status or force_display:
pass
elif (last_battery_msg_level_status[0] == f"{self.dev_data_battery_level}%"
elif (last_battery_level == self.dev_data_battery_level
or (self.dev_data_battery_level % 5) != 0):
return False

battery_msg = f"{self.dev_data_battery_level}%, {self.format_battery_status}"
if battery_msg == self.last_battery_msg and display_msg is False:
if battery_msg == self.last_battery_msg and force_display is False:
return False

self.last_battery_msg = battery_msg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class iCloud3EventLogCard extends HTMLElement {
}
//---------------------------------------------------------------------------
setConfig(config) {
const version = "3.0.15"
const version = "3.0.16"
const cardTitle = "iCloud3 v3 - Event Log"

const root = this.shadowRoot
Expand Down Expand Up @@ -986,7 +986,7 @@ class iCloud3EventLogCard extends HTMLElement {
const versionSentFlag = root.getElementById("versionSentFlag")

try {
const ic3DirEvlogVersion = hass.states['sensor.icloud3_event_log'].attributes['versionEvLog']
const ic3DirEvlogVersion = hass.states['sensor.icloud3_event_log'].attributes['version_evlog']
const updateTime = hass.states['sensor.icloud3_event_log'].attributes['update_time']
const userMessage = hass.states['sensor.icloud3_event_log'].attributes['user_message']
const aboutVersion = root.getElementById("aboutVersion")
Expand Down Expand Up @@ -1620,9 +1620,9 @@ class iCloud3EventLogCard extends HTMLElement {
this._displayTimeMsgR(infoTimeText)
}

if (versionSentFlag.innerText == 0) {
this._issue_evlog_version_svc_call()
}
// if (versionSentFlag.innerText == 0) {
// this._issue_evlog_version_svc_call()
// }
}

//---------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions custom_components/icloud3/helpers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ def format_gps(latitude, longitude, accuracy, latitude_to=None, longitude_to=Non
if longitude is None or latitude is None:
gps_text = UNKNOWN

elif Gb.display_gps_lat_long_flag is False:
gps_text = f"/±{accuracy:.0f}m"
# elif Gb.display_gps_lat_long_flag is False:
# gps_text = f"/±{accuracy:.0f}m"

else:
accuracy_text = (f"/±{accuracy:.0f}m)") if accuracy > 0 else ")"
Expand Down
8 changes: 5 additions & 3 deletions custom_components/icloud3/helpers/time_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,12 @@ def secs_to_time_age_str(time_secs):
if time_secs < 1 or time_secs == HIGH_INTEGER:
return '00:00:00'

time_age_str = (f"{secs_to_time(time_secs)} "
f"({secs_to_time_str(secs_since(time_secs))} ago)")
age_secs = secs_since(time_secs)
if age_secs >= 86400:
return f"{age_secs/86400:.1f} days ago"

return time_age_str
return (f"{secs_to_time(time_secs)} "
f"({secs_to_time_str(age_secs)} ago)")

#--------------------------------------------------------------------
def secs_to_age_str(time_secs):
Expand Down
1 change: 1 addition & 0 deletions custom_components/icloud3/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"required_field": "This parameter must be specified",
"required_field_device": "A device providing location data must be selected from the Family Share, Find-my-Friends, or iOS App devices lists",
"no_device_selected": "A device providing location data must be selected",
"no_add_entities_device_tracker_fct": "The HA component for adding devices is not available. HA MUST BE RESTARTED",

"unknown_devicename": "The device that was previously selected can no longer be identified. It`s name may have been changed or it may have been deleted. Reselect the device to be tracked or monitored",
"unknown_value": "The value of this parameter in the iCloud3 configuration file is unknown or invalid. It must be selected again",
Expand Down
39 changes: 33 additions & 6 deletions custom_components/icloud3/support/event_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
CONF_EVLOG_BTNCONFIG_URL,
)

from ..helpers.common import instr, circle_letter
from ..helpers.common import instr, circle_letter, str_to_list, list_to_str
from ..helpers.messaging import log_exception, log_info_msg, log_warning_msg, _traceha, _trace
from ..helpers.time_util import time_to_12hrtime, datetime_now, time_now_secs

Expand Down Expand Up @@ -111,6 +111,7 @@ def initialize(self):
self.evlog_attrs = {}
self.evlog_attrs["version_ic3"] = Gb.version
self.evlog_attrs["version_evlog"] = Gb.version_evlog
self.evlog_attrs["versionEvLog"] = Gb.version_evlog
self.evlog_attrs["log_level_debug"] = ''
self.evlog_attrs["run_mode"] = 'Initialize'
self.evlog_attrs["evlog_btn_urls"] = self.evlog_btn_urls
Expand Down Expand Up @@ -174,6 +175,7 @@ def setup_event_log_trackable_device_info(self):
self.evlog_btn_urls['btnConfig'] = Gb.evlog_btnconfig_url
self.evlog_attrs["version_ic3"] = Gb.version
self.evlog_attrs["version_evlog"] = Gb.version_evlog
self.evlog_attrs["versionEvLog"] = Gb.version_evlog
self.evlog_attrs["run_mode"] = "Initialize"
self.evlog_attrs["evlog_btn_urls"] = self.evlog_btn_urls
self.evlog_attrs["update_time"] = "setup"
Expand Down Expand Up @@ -230,7 +232,8 @@ def post_event(self, devicename, event_text='+'):
in_last_few_recds = [v for v in self.evlog_table[:8] \
if (v[ELR_DEVICENAME] == devicename \
and v[ELR_TEXT] == event_text \
and v[ELR_TEXT].startswith(EVLOG_TIME_RECD) is False)]
and v[ELR_TEXT].startswith(EVLOG_TIME_RECD) is False
and v[ELR_TEXT].startswith('Battery') is False)]
if in_last_few_recds != []:
return

Expand Down Expand Up @@ -268,16 +271,16 @@ def post_event(self, devicename, event_text='+'):
# If tracking from more than one zone and the tfz results are being displayed,
# display tfz zone name in the time field. Capitalize if going towards
if devicename.startswith('*') is False:
Device = Gb.Devices_by_devicename.get(devicename)
if Device:
if Device := Gb.Devices_by_devicename.get(devicename):
Device.last_evlog_msg_secs = time_now_secs()
from_zone_display_as = Device.FromZone_BeingUpdated.from_zone_display_as
if event_text.startswith(EVLOG_TIME_RECD):
this_update_time = f"»{from_zone_display_as[:6]}"
if (Device.FromZone_BeingUpdated is Device.FromZone_TrackFrom
and Device.FromZone_BeingUpdated is not Device.FromZone_Home):
this_update_time = this_update_time.upper()
elif from_zone_display_as != HOME_FNAME:

elif Device.FromZone_BeingUpdated is not Device.FromZone_Home:
this_update_time = f"»{from_zone_display_as[:6]}"

except Exception as err:
Expand Down Expand Up @@ -555,6 +558,7 @@ def _insert_event_log_recd(self, event_recd):

self.evlog_table.insert(0, event_recd)


#------------------------------------------------------
def _shrink_evlog_table(self, shrink_cnt):
'''
Expand Down Expand Up @@ -641,6 +645,9 @@ def _filtered_evlog_recds(self, devicename='', max_recds=HIGH_INTEGER, selected_
devicename = self.devicename
time_text_recds = self._extract_filtered_evlog_recds(devicename)

if Gb.display_gps_lat_long_flag is False:
time_text_recds = [self._apply_gps_filter(el_recd) for el_recd in time_text_recds]

if max_recds < HIGH_INTEGER:
recd_cnt = len(time_text_recds)
time_text_recds = time_text_recds[0:max_recds]
Expand Down Expand Up @@ -678,7 +685,7 @@ def _extract_filtered_evlog_recds(self, devicename):

if Device := Gb.Devices_by_devicename.get(devicename):
filter_record = (Device.primary_data_source == IOSAPP) \
or Device.is_monitored
or Device.is_monitored
else:
Device = None
filter_record = False
Expand Down Expand Up @@ -711,6 +718,26 @@ def _extract_filtered_evlog_recds(self, devicename):

return []

#--------------------------------------------------------------------
@staticmethod
def _apply_gps_filter(el_recd):
'''
Filter the gps coordinates out of the record based on the config parameter
Convert 'GPS-(27.72683, -80.39055/±33m)' to 'GPS-/±33m'
'''
el_time, el_text = el_recd
if el_text.find('GPS-(') == -1:
return [el_time, el_text]

check_for_gps_flag = True
while check_for_gps_flag:
gps_s_pos = el_text.find('GPS-(') + 4
gps_acc_pos = el_text.find('/±', gps_s_pos)
gps_e_pos = el_text.find(')', gps_s_pos)
el_text = el_text[:gps_s_pos] + el_text[gps_acc_pos:gps_e_pos] + el_text[gps_e_pos+1:]
check_for_gps_flag = el_text.find('GPS-(') >= 0
return [el_time, el_text.replace('GPS-, ', '')]

#--------------------------------------------------------------------
@staticmethod
def _filter_record(Device, el_recd_text):
Expand Down
7 changes: 4 additions & 3 deletions custom_components/icloud3/support/service_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def update_service_handler(action_entry=None, action_fname=None, devicename=None
action_option = action_entry.replace(action, '').strip()

# EvLog version sent from the EvLog program already set, ignore the svc call
if action == 'event_log_version' and Gb.evlog_version == action_option:
if action == 'event_log_version': # and Gb.evlog_version == action_option:
return

devicename_msg = devicename if devicename in Gb.Devices_by_devicename else None
Expand Down Expand Up @@ -408,10 +408,11 @@ def _handle_global_action(global_action, action_option):
return

elif global_action == 'event_log_version':
return
# Gb.evlog_version = action_option
# Gb.EvLog.evlog_attrs["version_evlog"] = action_option
Gb.conf_profile['event_log_version'] = action_option
config_file.write_storage_icloud3_configuration_file()
# Gb.conf_profile['event_log_version'] = action_option
# config_file.write_storage_icloud3_configuration_file()


#--------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions custom_components/icloud3/support/start_ic3.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,12 +725,19 @@ def check_ic3_event_log_file_version():
f"{CRLF_DOT}File-{www_evlog_js_filename_msg}")
post_event(event_msg)

if Gb.evlog_version != www_version_text:
Gb.evlog_version = Gb.conf_profile['event_log_version'] = www_version_text
config_file.write_storage_icloud3_configuration_file()

return

try:
_copy_image_files_to_www_directory(www_evlog_js_directory)
shutil.copy(ic3_evlog_js_filename, www_evlog_js_filename)

Gb.evlog_version = Gb.conf_profile['event_log_version'] = www_version_text
config_file.write_storage_icloud3_configuration_file()

post_startup_alert('Event Log was updated. Browser refresh needed')
event_msg =(f"{EVLOG_ALERT}"
f"EVENT LOG ALERT > iCloud3 Event Log was updated to v{ic3_version_text}"
Expand Down
1 change: 1 addition & 0 deletions custom_components/icloud3/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"required_field": "This parameter must be specified",
"required_field_device": "A device providing location data must be selected from the Family Share, Find-my-Friends, or iOS App devices lists",
"no_device_selected": "A device providing location data must be selected",
"no_add_entities_device_tracker_fct": "The HA component for adding devices is not available. HA MUST BE RESTARTED",

"unknown_devicename": "The device that was previously selected can no longer be identified. It`s name may have been changed or it may have been deleted. Reselect the device to be tracked or monitored",
"unknown_value": "The value of this parameter in the iCloud3 configuration file is unknown or invalid. It must be selected again",
Expand Down

0 comments on commit 8add1d3

Please sign in to comment.