Skip to content

Commit

Permalink
Merge pull request #6 from siamzam/netgear-define-a-constant-instead-…
Browse files Browse the repository at this point in the history
…of-duplicating-string-literals

Netgear - refactored duplicated string literals
  • Loading branch information
siamzam committed Oct 10, 2023
2 parents 30160b4 + d0fbe4d commit 8ab18e3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 35 deletions.
32 changes: 18 additions & 14 deletions homeassistant/components/netgear/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
MODE_ROUTER = "0"
MODE_AP = "1"

STR_MDI_CELLPHONE = "mdi:cellphone"
STR_MDI_TABLET = "mdi:tablet"
STR_MDI_PLAY_NETWORK = "mdi:play-network"

# models using port 80 instead of 5000
MODELS_PORT_80 = [
"Orbi",
Expand Down Expand Up @@ -77,40 +81,40 @@
0: "mdi:access-point-network", # Router (Orbi ...)
1: "mdi:book-open-variant", # Amazon Kindle
2: "mdi:android", # Android Device
3: "mdi:cellphone", # Android Phone
4: "mdi:tablet", # Android Tablet
3: STR_MDI_CELLPHONE, # Android Phone
4: STR_MDI_TABLET, # Android Tablet
5: "mdi:router-wireless", # Apple Airport Express
6: "mdi:disc-player", # Blu-ray Player
7: "mdi:router-network", # Bridge
8: "mdi:play-network", # Cable STB
8: STR_MDI_PLAY_NETWORK, # Cable STB
9: "mdi:camera", # Camera
10: "mdi:router-network", # Router
11: "mdi:play-network", # DVR
11: STR_MDI_PLAY_NETWORK, # DVR
12: "mdi:gamepad-variant", # Gaming Console
13: "mdi:monitor", # iMac
14: "mdi:tablet", # iPad
15: "mdi:tablet", # iPad Mini
16: "mdi:cellphone", # iPhone 5/5S/5C
17: "mdi:cellphone", # iPhone
14: STR_MDI_TABLET, # iPad
15: STR_MDI_TABLET, # iPad Mini
16: STR_MDI_CELLPHONE, # iPhone 5/5S/5C
17: STR_MDI_CELLPHONE, # iPhone
18: "mdi:ipod", # iPod Touch
19: "mdi:linux", # Linux PC
20: "mdi:apple-finder", # Mac Mini
21: "mdi:desktop-tower", # Mac Pro
22: "mdi:laptop", # MacBook
23: "mdi:play-network", # Media Device
23: STR_MDI_PLAY_NETWORK, # Media Device
24: "mdi:network", # Network Device
25: "mdi:play-network", # Other STB
25: STR_MDI_PLAY_NETWORK, # Other STB
26: "mdi:power-plug", # Powerline
27: "mdi:printer", # Printer
28: "mdi:access-point", # Repeater
29: "mdi:play-network", # Satellite STB
29: STR_MDI_PLAY_NETWORK, # Satellite STB
30: "mdi:scanner", # Scanner
31: "mdi:play-network", # SlingBox
32: "mdi:cellphone", # Smart Phone
31: STR_MDI_PLAY_NETWORK, # SlingBox
32: STR_MDI_CELLPHONE, # Smart Phone
33: "mdi:nas", # Storage (NAS)
34: "mdi:switch", # Switch
35: "mdi:television", # TV
36: "mdi:tablet", # Tablet
36: STR_MDI_TABLET, # Tablet
37: "mdi:desktop-classic", # UNIX PC
38: "mdi:desktop-tower-monitor", # Windows PC
39: "mdi:laptop", # Surface
Expand Down
38 changes: 20 additions & 18 deletions homeassistant/components/netgear/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class NetgearSensorEntityDescription(SensorEntityDescription):
value: Callable = lambda data: data
index: int = 0

STR_MDI_UPLOAD = "mdi:upload"
STR_MDI_DOWNLOAD = "mdi:download"

SENSOR_TRAFFIC_TYPES = [
NetgearSensorEntityDescription(
Expand All @@ -92,39 +94,39 @@ class NetgearSensorEntityDescription(SensorEntityDescription):
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload",
icon=STR_MDI_UPLOAD,
),
NetgearSensorEntityDescription(
key="NewTodayDownload",
translation_key="download_today",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
icon=STR_MDI_DOWNLOAD,
),
NetgearSensorEntityDescription(
key="NewYesterdayUpload",
translation_key="upload_yesterday",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload",
icon=STR_MDI_UPLOAD,
),
NetgearSensorEntityDescription(
key="NewYesterdayDownload",
translation_key="download_yesterday",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
icon=STR_MDI_DOWNLOAD,
),
NetgearSensorEntityDescription(
key="NewWeekUpload",
translation_key="upload_week",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload",
icon=STR_MDI_UPLOAD,
index=0,
value=lambda data: data[0],
),
Expand All @@ -134,7 +136,7 @@ class NetgearSensorEntityDescription(SensorEntityDescription):
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload",
icon=STR_MDI_UPLOAD,
index=1,
value=lambda data: data[1],
),
Expand All @@ -144,7 +146,7 @@ class NetgearSensorEntityDescription(SensorEntityDescription):
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
icon=STR_MDI_DOWNLOAD,
index=0,
value=lambda data: data[0],
),
Expand All @@ -154,7 +156,7 @@ class NetgearSensorEntityDescription(SensorEntityDescription):
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
icon=STR_MDI_DOWNLOAD,
index=1,
value=lambda data: data[1],
),
Expand All @@ -164,7 +166,7 @@ class NetgearSensorEntityDescription(SensorEntityDescription):
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload",
icon=STR_MDI_UPLOAD,
index=0,
value=lambda data: data[0],
),
Expand All @@ -174,7 +176,7 @@ class NetgearSensorEntityDescription(SensorEntityDescription):
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload",
icon=STR_MDI_UPLOAD,
index=1,
value=lambda data: data[1],
),
Expand All @@ -184,7 +186,7 @@ class NetgearSensorEntityDescription(SensorEntityDescription):
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
icon=STR_MDI_DOWNLOAD,
index=0,
value=lambda data: data[0],
),
Expand All @@ -194,7 +196,7 @@ class NetgearSensorEntityDescription(SensorEntityDescription):
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
icon=STR_MDI_DOWNLOAD,
index=1,
value=lambda data: data[1],
),
Expand All @@ -204,7 +206,7 @@ class NetgearSensorEntityDescription(SensorEntityDescription):
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload",
icon=STR_MDI_UPLOAD,
index=0,
value=lambda data: data[0],
),
Expand All @@ -214,7 +216,7 @@ class NetgearSensorEntityDescription(SensorEntityDescription):
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload",
icon=STR_MDI_UPLOAD,
index=1,
value=lambda data: data[1],
),
Expand All @@ -224,7 +226,7 @@ class NetgearSensorEntityDescription(SensorEntityDescription):
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
icon=STR_MDI_DOWNLOAD,
index=0,
value=lambda data: data[0],
),
Expand All @@ -234,7 +236,7 @@ class NetgearSensorEntityDescription(SensorEntityDescription):
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
icon=STR_MDI_DOWNLOAD,
index=1,
value=lambda data: data[1],
),
Expand All @@ -247,15 +249,15 @@ class NetgearSensorEntityDescription(SensorEntityDescription):
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfDataRate.MEGABITS_PER_SECOND,
device_class=SensorDeviceClass.DATA_RATE,
icon="mdi:upload",
icon=STR_MDI_UPLOAD,
),
NetgearSensorEntityDescription(
key="NewOOKLADownlinkBandwidth",
translation_key="downlink_bandwidth",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=UnitOfDataRate.MEGABITS_PER_SECOND,
device_class=SensorDeviceClass.DATA_RATE,
icon="mdi:download",
icon=STR_MDI_DOWNLOAD,
),
NetgearSensorEntityDescription(
key="AveragePing",
Expand Down
7 changes: 4 additions & 3 deletions homeassistant/components/netgear/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class NetgearSwitchEntityDescription(
):
"""Class describing Netgear Switch entities."""

STR_MDI_WIFI = "mdi:wifi"

ROUTER_SWITCH_TYPES = [
NetgearSwitchEntityDescription(
Expand Down Expand Up @@ -83,23 +84,23 @@ class NetgearSwitchEntityDescription(
NetgearSwitchEntityDescription(
key="2g_guest_wifi",
translation_key="2g_guest_wifi",
icon="mdi:wifi",
icon=STR_MDI_WIFI,
entity_category=EntityCategory.CONFIG,
update=lambda router: router.api.get_2g_guest_access_enabled,
action=lambda router: router.api.set_2g_guest_access_enabled,
),
NetgearSwitchEntityDescription(
key="5g_guest_wifi",
translation_key="5g_guest_wifi",
icon="mdi:wifi",
icon=STR_MDI_WIFI,
entity_category=EntityCategory.CONFIG,
update=lambda router: router.api.get_5g_guest_access_enabled,
action=lambda router: router.api.set_5g_guest_access_enabled,
),
NetgearSwitchEntityDescription(
key="smart_connect",
translation_key="smart_connect",
icon="mdi:wifi",
icon=STR_MDI_WIFI,
entity_category=EntityCategory.CONFIG,
update=lambda router: router.api.get_smart_connect_enabled,
action=lambda router: router.api.set_smart_connect_enabled,
Expand Down

0 comments on commit 8ab18e3

Please sign in to comment.