Skip to content

Fix empty NetworkName - #189

Merged
nijel merged 18 commits into
masterfrom
copilot/fix-empty-network-name
Feb 4, 2026
Merged

Fix empty NetworkName#189
nijel merged 18 commits into
masterfrom
copilot/fix-empty-network-name

Conversation

Copilot AI commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR addresses the issue where GetNetworkInfo() returns an empty NetworkName even when NetworkCode is available (e.g., "240 24").

Changes Made

  • Created dedicated example (network_info.py) demonstrating how to use gammu.GSMNetworks for network name lookup
  • Updated async.py example to show the lookup pattern when NetworkName is empty
  • Added comprehensive tests for GSMNetworks and GSMCountries dictionaries in test_data.py
  • Updated GetNetworkInfo() docstring in C code to document the GSMNetworks lookup pattern
  • Fixed NetworkName to use UnicodeStringToPython for proper Unicode string handling
  • Added automatic detection for Unicode vs ASCII strings for backward compatibility with dummy backend
  • Simplified detection logic based on code review feedback
  • Added proper NULL check for error handling
  • Addressed code review feedback on consistency
  • Passed security scanning (0 alerts)

Solution

The solution leverages the existing gammu.GSMNetworks dictionary which is already exported from the C extension. This dictionary contains network code to network name mappings from Gammu's built-in database. When NetworkName is empty from the phone, users can now look it up using the NetworkCode.

Additionally, NetworkName is now properly decoded as a Unicode string using UnicodeStringToPython for real phones, with automatic fallback to ASCII string handling (via LocaleStringToPython) for backward compatibility with the dummy backend implementation.

Security Summary

No security vulnerabilities discovered or introduced. All security scans passed with 0 alerts.

Original prompt

This section details on the original issue you should resolve

<issue_title>GetNetworkInfo() network name netinfo['NetworkName'] is empty</issue_title>
<issue_description>NetworkCode is "240 24" and I would think it should populate NetworkName from https://wammu.eu/tools/networks/ but it does not. Am I doing something wrong maybe?

Also would like to know if it is at all possible to send a custom command to the modem via gammu, or if I then need to extend gammu in some way?

Kind regards
Jens


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
</issue_description>

Comments on the Issue (you are @copilot in this section)

@nijel This is network name as returned by phone, it might be empty in many cases. You can use `gammu.GSMNetworks` for lookup in Gammu networks database.

💡 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.

Copilot AI and others added 5 commits February 4, 2026 14:36
Co-authored-by: nijel <212189+nijel@users.noreply.github.com>
Co-authored-by: nijel <212189+nijel@users.noreply.github.com>
Co-authored-by: nijel <212189+nijel@users.noreply.github.com>
Co-authored-by: nijel <212189+nijel@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix empty NetworkName in GetNetworkInfo() function Document GSMNetworks lookup for empty NetworkName Feb 4, 2026
Copilot AI requested a review from nijel February 4, 2026 14:40
@nijel

nijel commented Feb 4, 2026

Copy link
Copy Markdown
Member

pre-commit.ci autofix

@nijel

nijel commented Feb 4, 2026

Copy link
Copy Markdown
Member

@copilot This addition is useful, but I believe NetworkName should be a Unicode string, and thus decoding using UnicodeStringToPython is missing for it. The dummy backend, which is used for testing, is currently wrongly using ASCII strings instead.

Co-authored-by: nijel <212189+nijel@users.noreply.github.com>

Copilot AI commented Feb 4, 2026

Copy link
Copy Markdown
Contributor Author

@copilot This addition is useful, but I believe NetworkName should be a Unicode string, and thus decoding using UnicodeStringToPython is missing for it. The dummy backend, which is used for testing, i...

Fixed in 09e7626. NetworkName now uses UnicodeStringToPython() for proper Unicode string handling instead of being treated as an ASCII string.

@nijel
nijel marked this pull request as ready for review February 4, 2026 15:12
@nijel
nijel enabled auto-merge (squash) February 4, 2026 15:13
@nijel

nijel commented Feb 4, 2026

Copy link
Copy Markdown
Member

@copilot Can we add detection whether string is unicode or ascii and handle it accordingly? This would make it compatible with the current dummy backend implementation.

Co-authored-by: nijel <212189+nijel@users.noreply.github.com>
auto-merge was automatically disabled February 4, 2026 15:21

Head branch was pushed to by a user without write access

Copilot AI commented Feb 4, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Can we add detection whether string is unicode or ascii and handle it accordingly? This would make it compatible with the current dummy backend implementation.

Added in f2f9087. NetworkName now detects whether the string is Unicode or ASCII using a heuristic (checks if second byte is 0 for Unicode 2-byte encoding) and handles accordingly: UnicodeStringToPython() for Unicode strings, LocaleStringToPython() for ASCII strings. This maintains backward compatibility with the dummy backend.

@nijel
nijel enabled auto-merge (squash) February 4, 2026 15:26
@nijel nijel changed the title Document GSMNetworks lookup for empty NetworkName Fix empty NetworkName Feb 4, 2026
@nijel
nijel merged commit 0e95555 into master Feb 4, 2026
49 checks passed
@nijel
nijel deleted the copilot/fix-empty-network-name branch February 4, 2026 17:21
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.

GetNetworkInfo() network name netinfo['NetworkName'] is empty

2 participants