Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add netgear_lte connection sensors #22558

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/netgear_lte/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from . import sensor_types

REQUIREMENTS = ['eternalegypt==0.0.5']
REQUIREMENTS = ['eternalegypt==0.0.6']

_LOGGER = logging.getLogger(__name__)

Expand Down
11 changes: 11 additions & 0 deletions homeassistant/components/netgear_lte/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ async def async_setup_platform(
sensors.append(SMSSensor(modem_data, sensor_type))
elif sensor_type == SENSOR_USAGE:
sensors.append(UsageSensor(modem_data, sensor_type))
else:
sensors.append(GenericSensor(modem_data, sensor_type))

async_add_entities(sensors)

Expand Down Expand Up @@ -106,3 +108,12 @@ class UsageSensor(LTESensor):
def state(self):
"""Return the state of the sensor."""
return round(self.modem_data.data.usage / 1024**2, 1)


class GenericSensor(LTESensor):
"""Sensor entity with raw state."""

@property
def state(self):
"""Return the state of the sensor."""
return getattr(self.modem_data.data, self.sensor_type)
13 changes: 13 additions & 0 deletions homeassistant/components/netgear_lte/sensor_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@
SENSOR_UNITS = {
SENSOR_SMS: 'unread',
SENSOR_USAGE: 'MiB',
'radio_quality': '%',
'rx_level': 'dBm',
'tx_level': 'dBm',
'upstream': None,
'wire_connected': None,
Copy link
Member

@rohankapoorcom rohankapoorcom Apr 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, on second thought shouldn't wire_connected and mobile_connected be binary sensors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. For mobile_connected, states disconnected/standby/connected have been observed. Maybe I should name it mobile_status instead?

The wire_connected is currently binary but I am guessing we could discover more states in the future (from the undocumented API). I am not sure what to do in such a case but I would probably rename it along with the first one.

It seems like roaming would indeed be binary, though.

I will think a bit about this and make a follow-up PR before the next beta. Thanks!

'mobile_connected': None,
'connection_text': None,
'connection_type': None,
'current_ps_service_type': None,
'register_network_display': None,
'roaming': None,
'current_band': None,
'cell_id': None,
}

ALL = list(SENSOR_UNITS)
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ ephem==3.7.6.0
epson-projector==0.1.3

# homeassistant.components.netgear_lte
eternalegypt==0.0.5
eternalegypt==0.0.6

# homeassistant.components.keyboard_remote
# evdev==0.6.1
Expand Down