More details about SMS modem (#75694)

This commit is contained in:
Paul Annekov 2022-09-26 04:49:55 +03:00 committed by GitHub
parent 92612c9fe3
commit 1b17c83095
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 115 additions and 88 deletions

View file

@ -21,10 +21,16 @@ class Gateway:
self._worker.configure(config)
self._hass = hass
self._first_pull = True
self.manufacturer = None
self.model = None
self.firmware = None
async def init_async(self):
"""Initialize the sms gateway asynchronously."""
"""Initialize the sms gateway asynchronously. This method is also called in config flow to verify connection."""
await self._worker.init_async()
self.manufacturer = await self.get_manufacturer_async()
self.model = await self.get_model_async()
self.firmware = await self.get_firmware_async()
def sms_pull(self, state_machine):
"""Pull device.
@ -156,7 +162,37 @@ class Gateway:
async def get_network_info_async(self):
"""Get the current network info of the modem."""
return await self._worker.get_network_info_async()
network_info = await self._worker.get_network_info_async()
# Looks like there is a bug and it's empty for any modem https://github.com/gammu/python-gammu/issues/31, so try workaround
if not network_info["NetworkName"]:
network_info["NetworkName"] = gammu.GSMNetworks.get(
network_info["NetworkCode"]
)
return network_info
async def get_manufacturer_async(self):
"""Get the manufacturer of the modem."""
return await self._worker.get_manufacturer_async()
async def get_model_async(self):
"""Get the model of the modem."""
model = await self._worker.get_model_async()
if not model or not model[0]:
return
display = model[0] # Identification model
if model[1]: # Real model
display = f"{display} ({model[1]})"
return display
async def get_firmware_async(self):
"""Get the firmware information of the modem."""
firmware = await self._worker.get_firmware_async()
if not firmware or not firmware[0]:
return
display = firmware[0] # Version
if firmware[1]: # Date
display = f"{display} ({firmware[1]})"
return display
async def terminate_async(self):
"""Terminate modem connection."""