Skip to content

Commit

Permalink
refactor: remove defunct service: clear_history (#2324)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbrunt57 authored Jul 18, 2024
1 parent b7e7559 commit fd814e7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 98 deletions.
38 changes: 0 additions & 38 deletions custom_components/alexa_media/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,44 +84,6 @@ async def unregister(self):
)
self.hass.services.async_remove(DOMAIN, SERVICE_FORCE_LOGOUT)

@_catch_login_errors
async def clear_history(self, call):
"""Handle clear history service request.
Arguments
call.ATTR_EMAIL {List[str: None]} -- Case-sensitive Alexa emails.
Default is all known emails.
call.ATTR_NUM_ENTRIES {int: 50} -- Number of entries to delete.
Returns
bool -- True if deletion successful
"""
_LOGGER.debug("call %s", call)
requested_emails = call.data.get(ATTR_EMAIL)
items: int = int(call.data.get(ATTR_NUM_ENTRIES))

_LOGGER.debug(
"Service clear_history called for: %i items for %s", items, requested_emails
)
success = False
for email, account_dict in self.hass.data[DATA_ALEXAMEDIA]["accounts"].items():
if requested_emails and email not in requested_emails:
continue
login_obj = account_dict["login_obj"]
try:
await AlexaAPI.clear_history(login_obj, items)
except AlexapyLoginError:
report_relogin_required(self.hass, login_obj, email)
success = True
except AlexapyConnectionError:
_LOGGER.error(
"Unable to connect to Alexa for %s;"
" check your network connection and try again",
hide_email(email),
)
return success

@_catch_login_errors
async def force_logout(self, call) -> bool:
"""Handle force logout service request.
Expand Down
14 changes: 0 additions & 14 deletions custom_components/alexa_media/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,6 @@
}
},
"services": {
"clear_history": {
"name": "Clear Amazon Voice History",
"description": "Clear last entries from Alexa Voice history for each Alexa account.",
"fields": {
"email": {
"name": "Email address",
"description": "Accounts to clear. Empty will clear all."
},
"entries": {
"name": "Number of Entries",
"description": "Number of entries to clear from 1 to 50. If empty, clear 50."
}
}
},
"force_logout": {
"name": "Force Logout",
"description": "Force account to logout. Used mainly for debugging.",
Expand Down
82 changes: 38 additions & 44 deletions custom_components/alexa_media/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,38 @@
"reauth_successful": "Alexa Media Player successfully reauthenticated. Please ignore the \"Aborted\" message from HA."
},
"error": {
"2fa_key_invalid": "Invalid Built-In 2FA key",
"connection_error": "Error connecting; check network and retry",
"identifier_exists": "Email for Alexa URL already registered",
"invalid_credentials": "Invalid credentials",
"invalid_url": "URL is invalid: {message}",
"unable_to_connect_hass_url": "Unable to connect to Home Assistant url. Please check the External Url under Configuration -> General",
"2fa_key_invalid": "Invalid Built-In 2FA key",
"unable_to_connect_hass_url": "Unable to connect to Home Assistant URL. Please check the Internal URL under Configuration -> General",
"unknown_error": "Unknown error: {message}"
},
"step": {
"user": {
"data": {
"url": "Amazon region domain (e.g., amazon.co.uk)",
"email": "Email Address",
"password": "Password",
"securitycode": "[%key_id:55616596%]",
"otp_secret": "Built-in 2FA App Key - This is 52 characters, not six!",
"hass_url": "Url to access Home Assistant",
"include_devices": "Included device (comma separated)",
"exclude_devices": "Excluded device (comma separated)",
"scan_interval": "Seconds between scans",
"queue_delay": "Seconds to wait to queue commands together",
"extended_entity_discovery": "Include devices connected via Echo",
"debug": "Advanced debugging"
},
"description": "Required *",
"title": "Alexa Media Player - Configuration"
},
"proxy_warning": {
"data": {
"proxy_warning": "Ignore and Continue - I understand that no support for login issues are provided for bypassing this warning."
},
"description": "The HA server cannot connect to the URL provided: {hass_url}.\n> {error}\n\nTo fix this, please confirm your **HA server** can reach {hass_url}. This field is from the External Url under Configuration -> General but you can try your internal url.\n\nIf you are **certain** your client can reach this url, you can bypass this warning.",
"description": "The HA server cannot connect to the URL provided: {hass_url}.\n> {error}\n\nTo fix this, please confirm your **HA server** can reach {hass_url}. This field is from the External URL under Configuration -> General but you can try your internal URL.\n\nIf you are **certain** your client can reach this URL, you can bypass this warning.",
"title": "Alexa Media Player - Unable to Connect to HA URL"
},
"totp_register": {
Expand All @@ -28,70 +46,46 @@
},
"description": "**{email} - alexa.{url}** \nHave you successfully confirmed an OTP from the Built-in 2FA App Key with Amazon? \n >OTP Code {message}",
"title": "Alexa Media Player - OTP Confirmation"
},
"user": {
"data": {
"debug": "Advanced debugging",
"email": "Email Address",
"exclude_devices": "Excluded device (comma separated)",
"hass_url": "Url to access Home Assistant",
"include_devices": "Included device (comma separated)",
"otp_secret": "Built-in 2FA App Key (automatically generate 2FA Codes). This is not six digits long.",
"password": "Password",
"scan_interval": "Seconds between scans",
"securitycode": "[%key_id:55616596%]",
"url": "Amazon region domain (e.g., amazon.co.uk)"
},
"description": "Please confirm the information below. For legacy configuration, disable `Use Login Proxy method` option.",
"title": "Alexa Media Player - Configuration"
}
}
},
"options": {
"step": {
"init": {
"data": {
"hass_url": "Public URL to access Home Assistant (including trailing '/')",
"include_devices": "Included device (comma separated)",
"exclude_devices": "Excluded device (comma separated)",
"scan_interval": "Seconds between scans",
"queue_delay": "Seconds to wait to queue commands together",
"extended_entity_discovery": "Include devices connected via Echo",
"public_url": "Public URL to access Home Assistant (including trailing '/')",
"queue_delay": "Seconds to wait to queue commands together"
}
"debug": "Advanced debugging"
},
"description": "Required *",
"title": "Alexa Media Player - Reconfiguration"
}
}
},
"services": {
"clear_history": {
"description": "Clear last entries from Alexa Voice history for each Alexa account.",
"fields": {
"email": {
"description": "Accounts to clear. Empty will clear all.",
"name": "Email address"
},
"entries": {
"description": "Number of entries to clear from 1 to 50. If empty, clear 50.",
"name": "Number of Entries"
}
},
"name": "Clear Amazon Voice History"
},
"force_logout": {
"name": "Force Logout",
"description": "Force account to logout. Used mainly for debugging.",
"fields": {
"email": {
"description": "Accounts to clear. Empty will clear all.",
"name": "Email address"
"name": "Email address",
"description": "Accounts to clear. Empty will clear all."
}
},
"name": "Force Logout"
}
},
"update_last_called": {
"name": "Update Last Called Sensor",
"description": "Forces update of last_called echo device for each Alexa account.",
"fields": {
"email": {
"description": "List of Alexa accounts to update. If empty, will update all known accounts.",
"name": "Email address"
"name": "Email address",
"description": "List of Alexa accounts to update. If empty, will update all known accounts."
}
},
"name": "Update Last Called Sensor"
}
}
}
}
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ line_length=88
indent = " "
# will group `import x` and `from x import` of the same module.
force_sort_within_sections = true
sections = FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
default_section = THIRDPARTY
sections = FUTURE,STDLIB,THIRD-PARTY,FIRSTPARTY,LOCALFOLDER
default_section = THIRD-PARTY
known_first_party = alexa_media,tests
forced_separate = tests
combine_as_imports = true
Expand Down

0 comments on commit fd814e7

Please sign in to comment.