Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 15, 2025

This PR resolves the SyntaxWarning messages about invalid escape sequences that users were experiencing when using the Asterisk integration with Python 3.13+.

Problem

Users reported seeing warnings like:

/usr/local/lib/python3.13/site-packages/asterisk/ami/client.py:52: SyntaxWarning: invalid escape sequence '\.' asterisk_start_regex = re.compile('^Asterisk *Call *Manager/(?P<version>([0-9]+\.)*[0-9]+)', re.IGNORECASE)
/usr/local/lib/python3.13/site-packages/asterisk/ami/response.py:7: SyntaxWarning: invalid escape sequence '\-' key_regex = re.compile('^[a-zA-Z0-9_\-]+$')

Root Cause

The issue was caused by the asterisk-ami dependency being pinned to version 0.1.6 in manifest.json, which contained regex patterns with invalid escape sequences:

# Problematic patterns in asterisk-ami 0.1.6
asterisk_start_regex = re.compile('^Asterisk *Call *Manager/(?P<version>([0-9]+\.)*[0-9]+)', re.IGNORECASE)
key_regex = re.compile('^[a-zA-Z0-9_\-]+$')

Solution

Updated the asterisk-ami dependency requirement from ==0.1.6 to >=0.1.7. The upstream asterisk-ami library already fixed these warnings in version 0.1.7 (released January 2024) by using raw string literals:

# Fixed patterns in asterisk-ami 0.1.7+
asterisk_start_regex = re.compile(r'^Asterisk *Call *Manager/(?P<version>([0-9]+\.)*[0-9]+)', re.IGNORECASE)
key_regex = re.compile(r'^[a-zA-Z0-9_\-]+$')

Changes Made

  • Updated custom_components/asterisk/manifest.json to require asterisk-ami>=0.1.7
  • Updated dev-requirements.txt to use asterisk-ami>=0.1.7 for consistency
  • Verified that existing functionality remains unchanged
  • Confirmed that the warnings no longer appear with the updated dependency

This is a minimal change that leverages the existing upstream fix without modifying any of the integration's code. Users will automatically receive the corrected version when Home Assistant installs the integration's dependencies.

Fixes #114.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/search/repositories
    • Triggering command: `python -c
      import requests
      import json

try:
# Check GitHub for asterisk-ami project
response = requests.get('REDACTED', timeout=10)
if response.status_code == 200:
repos = response.json()['items']
for repo in repos[:3]:
print(f'Repo: {repo["full_name"]} - {repo["description"]}')
print(f'URL: {repo["html_url"]}')
print('---')
else:
print('Could not fetch from GitHub API')
except Exception as e:
print(f'Error: {e}')` (http block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Contributor Author

Copilot AI commented Sep 15, 2025

@TECH7Fox 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

- Update asterisk-ami dependency from 0.1.6 to >=0.1.7 in manifest.json
- Update dev-requirements.txt to use asterisk-ami>=0.1.7
- Fix addresses SyntaxWarnings about invalid escape sequences '\.' and '\-'
- The warnings were fixed upstream in asterisk-ami 0.1.7 by adding raw string prefixes

Co-authored-by: TECH7Fox <[email protected]>
@Copilot Copilot AI changed the title [WIP] invalid escape sequence Fix invalid escape sequence warnings by updating asterisk-ami dependency Sep 15, 2025
@Copilot Copilot AI requested a review from TECH7Fox September 15, 2025 00:36
Copilot finished work on behalf of TECH7Fox September 15, 2025 00:36
@TECH7Fox TECH7Fox marked this pull request as ready for review September 15, 2025 16:31
@TECH7Fox TECH7Fox merged commit 8593974 into main Sep 15, 2025
6 checks passed
@TECH7Fox TECH7Fox deleted the copilot/fix-114 branch September 15, 2025 16:32
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

Successfully merging this pull request may close these issues.

invalid escape sequence
2 participants