changed string formatting according to development guidelines

This commit is contained in:
tomaae 2020-03-16 19:02:54 +01:00
parent 7af3ef0bb3
commit 8ec4f9ade5
7 changed files with 31 additions and 39 deletions

View file

@ -63,7 +63,7 @@ def update_items(inst, mikrotik_controller, async_add_entities, sensors):
new_sensors = []
for sensor in SENSOR_TYPES:
item_id = "{}-{}".format(inst, sensor)
item_id = f"{inst}-{sensor}"
if item_id in sensors:
if sensors[item_id].enabled:
sensors[item_id].async_schedule_update_ha_state()
@ -99,7 +99,7 @@ class MikrotikControllerBinarySensor(BinarySensorDevice):
@property
def name(self):
"""Return the name."""
return "{} {}".format(self._inst, self._type[ATTR_LABEL])
return f"{self._inst} {self._type[ATTR_LABEL]}"
@property
def device_state_attributes(self):
@ -109,7 +109,7 @@ class MikrotikControllerBinarySensor(BinarySensorDevice):
@property
def unique_id(self):
"""Return a unique_id for this entity."""
return "{}-{}".format(self._inst.lower(), self._sensor.lower())
return f"{self._inst.lower()}-{self._sensor.lower()}"
@property
def available(self) -> bool:

View file

@ -80,8 +80,8 @@ def update_items(inst, mikrotik_controller, async_add_entities, tracked):
for uid in mikrotik_controller.data["interface"]:
if mikrotik_controller.data["interface"][uid]["type"] == "ether":
item_id = "{}-{}".format(
inst, mikrotik_controller.data["interface"][uid]["default-name"]
item_id = (
f"{inst}-{mikrotik_controller.data['interface'][uid]['default-name']}"
)
if item_id in tracked:
if tracked[item_id].enabled:
@ -143,12 +143,12 @@ class MikrotikControllerPortDeviceTracker(ScannerEntity):
@property
def name(self):
"""Return the name of the port."""
return "{} {}".format(self._inst, self._data["default-name"])
return f"{self._inst} {self._data['default-name']}"
@property
def unique_id(self):
"""Return a unique identifier for this port."""
return "{}-{}".format(self._inst.lower(), self._data["port-mac-address"])
return f"{self._inst.lower()}-{self._data['port-mac-address']}"
@property
def available(self) -> bool:

View file

@ -267,14 +267,14 @@ def fill_vals_proc(data, uid, vals_proc) -> dict:
if not _value:
_value = tmp
else:
_value = "{}{}".format(_value, tmp)
_value = f"{_value}{tmp}"
if "text" in val:
tmp = val["text"]
if not _value:
_value = tmp
else:
_value = "{}{}".format(_value, tmp)
_value = f"{_value}{tmp}"
if _name and _value:
if uid:

View file

@ -118,7 +118,7 @@ class MikrotikControllerData:
@property
def signal_update(self):
"""Event to signal new data."""
return "{}-update-{}".format(DOMAIN, self.name)
return f"{DOMAIN}-update-{self.name}"
# ---------------------------
# connected

View file

@ -256,7 +256,7 @@ class MikrotikAPI:
self.lock.release()
if not entry_found:
error = 'Parameter "{}" with value "{}" not found'.format(param, value)
error = f'Parameter "{param}" with value "{value}" not found'
raise ApiEntryNotFound(error)
return True
@ -321,7 +321,7 @@ class MikrotikAPI:
self.lock.release()
if not entry_found:
error = 'Script "{}" not found'.format(name)
error = f'Script "{name}" not found'
raise ApiEntryNotFound(error)
return True

View file

@ -109,7 +109,7 @@ def update_items(inst, mikrotik_controller, async_add_entities, sensors):
for sensor in SENSOR_TYPES:
if "traffic_" not in sensor:
item_id = "{}-{}".format(inst, sensor)
item_id = f"{inst}-{sensor}"
if item_id in sensors:
if sensors[item_id].enabled:
sensors[item_id].async_schedule_update_ha_state()
@ -123,11 +123,7 @@ def update_items(inst, mikrotik_controller, async_add_entities, sensors):
if "traffic_" in sensor:
for uid in mikrotik_controller.data["interface"]:
if mikrotik_controller.data["interface"][uid]["type"] == "ether":
item_id = "{}-{}-{}".format(
inst,
sensor,
mikrotik_controller.data["interface"][uid]["default-name"],
)
item_id = f"{inst}-{sensor}-{mikrotik_controller.data['interface'][uid]['default-name']}"
if item_id in sensors:
if sensors[item_id].enabled:
sensors[item_id].async_schedule_update_ha_state()
@ -169,7 +165,7 @@ class MikrotikControllerSensor(Entity):
@property
def name(self):
"""Return the name."""
return "{} {}".format(self._inst, self._type[ATTR_LABEL])
return f"{self._inst} {self._type[ATTR_LABEL]}"
@property
def state(self):
@ -199,7 +195,7 @@ class MikrotikControllerSensor(Entity):
@property
def unique_id(self):
"""Return a unique_id for this entity."""
return "{}-{}".format(self._inst.lower(), self._sensor.lower())
return f"{self._inst.lower()}-{self._sensor.lower()}"
@property
def unit_of_measurement(self):
@ -257,14 +253,12 @@ class MikrotikControllerTrafficSensor(MikrotikControllerSensor):
@property
def name(self):
"""Return the name."""
return "{} {} {}".format(self._inst, self._data["name"], self._type[ATTR_LABEL])
return f"{self._inst} {self._data['name']} {self._type[ATTR_LABEL]}"
@property
def unique_id(self):
"""Return a unique_id for this entity."""
return "{}-{}-{}".format(
self._inst.lower(), self._sensor.lower(), self._data["default-name"].lower()
)
return f"{self._inst.lower()}-{self._sensor.lower()}-{self._data['default-name'].lower()}"
@property
def device_info(self):

View file

@ -103,9 +103,7 @@ def update_items(inst, mikrotik_controller, async_add_entities, switches):
],
):
for uid in mikrotik_controller.data[sid]:
item_id = "{}-{}-{}".format(
inst, sid, mikrotik_controller.data[sid][uid]["name"]
)
item_id = f"{inst}-{sid}-{mikrotik_controller.data[sid][uid]['name']}"
if item_id in switches:
if switches[item_id].enabled:
switches[item_id].async_schedule_update_ha_state()
@ -170,14 +168,12 @@ class MikrotikControllerPortSwitch(MikrotikControllerSwitch):
@property
def name(self) -> str:
"""Return the name of the port."""
return "{} port {}".format(self._inst, self._data["default-name"])
return f"{self._inst} port {self._data['default-name']}"
@property
def unique_id(self) -> str:
"""Return a unique identifier for this port."""
return "{}-enable_switch-{}".format(
self._inst.lower(), self._data["port-mac-address"]
)
return f"{self._inst.lower()}-enable_switch-{self._data['port-mac-address']}"
@property
def icon(self):
@ -262,12 +258,12 @@ class MikrotikControllerNATSwitch(MikrotikControllerSwitch):
@property
def name(self) -> str:
"""Return the name of the NAT switch."""
return "{} NAT {}".format(self._inst, self._data["name"])
return f"{self._inst} NAT {self._data['name']}"
@property
def unique_id(self) -> str:
"""Return a unique identifier for this NAT switch."""
return "{}-nat_switch-{}".format(self._inst.lower(), self._data["name"])
return f"{self._inst.lower()}-nat_switch-{self._data['name']}"
@property
def icon(self):
@ -315,8 +311,9 @@ class MikrotikControllerNATSwitch(MikrotikControllerSwitch):
param = ".id"
value = None
for uid in self._ctrl.data["nat"]:
if self._ctrl.data["nat"][uid]["name"] == "{}:{}".format(
self._data["protocol"], self._data["dst-port"]
if (
self._ctrl.data["nat"][uid]["name"]
== f"{self._data['protocol']}:{self._data['dst-port']}"
):
value = self._ctrl.data["nat"][uid][".id"]
@ -331,8 +328,9 @@ class MikrotikControllerNATSwitch(MikrotikControllerSwitch):
param = ".id"
value = None
for uid in self._ctrl.data["nat"]:
if self._ctrl.data["nat"][uid]["name"] == "{}:{}".format(
self._data["protocol"], self._data["dst-port"]
if (
self._ctrl.data["nat"][uid]["name"]
== f"{self._data['protocol']}:{self._data['dst-port']}"
):
value = self._ctrl.data["nat"][uid][".id"]
@ -369,12 +367,12 @@ class MikrotikControllerScriptSwitch(MikrotikControllerSwitch):
@property
def name(self) -> str:
"""Return the name of the script switch."""
return "{} script {}".format(self._inst, self._data["name"])
return f"{self._inst} script {self._data['name']}"
@property
def unique_id(self) -> str:
"""Return a unique identifier for this script switch."""
return "{}-script_switch-{}".format(self._inst.lower(), self._data["name"])
return f"{self._inst.lower()}-script_switch-{self._data['name']}"
@property
def icon(self):