Use literal string interpolation in integrations R-S (f-strings) (#26392)
This commit is contained in:
parent
7203027cbf
commit
445c741b30
69 changed files with 129 additions and 149 deletions
|
@ -226,7 +226,7 @@ class RachioIro:
|
|||
|
||||
def __str__(self) -> str:
|
||||
"""Display the controller as a string."""
|
||||
return 'Rachio controller "{}"'.format(self.name)
|
||||
return f'Rachio controller "{self.name}"'
|
||||
|
||||
@property
|
||||
def controller_id(self) -> str:
|
||||
|
|
|
@ -87,12 +87,12 @@ class RachioControllerOnlineBinarySensor(RachioControllerBinarySensor):
|
|||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of this sensor including the controller name."""
|
||||
return "{} online".format(self._controller.name)
|
||||
return f"{self._controller.name} online"
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique id for this entity."""
|
||||
return "{}-online".format(self._controller.controller_id)
|
||||
return f"{self._controller.controller_id}-online"
|
||||
|
||||
@property
|
||||
def device_class(self) -> str:
|
||||
|
|
|
@ -72,7 +72,7 @@ class RachioSwitch(SwitchDevice):
|
|||
@property
|
||||
def name(self) -> str:
|
||||
"""Get a name for this switch."""
|
||||
return "Switch on {}".format(self._controller.name)
|
||||
return f"Switch on {self._controller.name}"
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
|
@ -113,12 +113,12 @@ class RachioStandbySwitch(RachioSwitch):
|
|||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the standby switch."""
|
||||
return "{} in standby mode".format(self._controller.name)
|
||||
return f"{self._controller.name} in standby mode"
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique id by combining controller id and purpose."""
|
||||
return "{}-standby".format(self._controller.controller_id)
|
||||
return f"{self._controller.controller_id}-standby"
|
||||
|
||||
@property
|
||||
def icon(self) -> str:
|
||||
|
@ -183,7 +183,7 @@ class RachioZone(RachioSwitch):
|
|||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique id by combining controller id and zone number."""
|
||||
return "{}-zone-{}".format(self._controller.controller_id, self.zone_id)
|
||||
return f"{self._controller.controller_id}-zone-{self.zone_id}"
|
||||
|
||||
@property
|
||||
def icon(self) -> str:
|
||||
|
|
|
@ -53,7 +53,7 @@ class RainBirdSwitch(SwitchDevice):
|
|||
self._rainbird = rb
|
||||
self._devid = dev_id
|
||||
self._zone = int(dev.get(CONF_ZONE))
|
||||
self._name = dev.get(CONF_FRIENDLY_NAME, "Sprinkler {}".format(self._zone))
|
||||
self._name = dev.get(CONF_FRIENDLY_NAME, f"Sprinkler {self._zone}")
|
||||
self._state = None
|
||||
self._duration = dev.get(CONF_TRIGGER_TIME)
|
||||
self._attributes = {"duration": self._duration, "zone": self._zone}
|
||||
|
|
|
@ -41,9 +41,9 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
DATA_LISTENER = "listener"
|
||||
|
||||
PROGRAM_UPDATE_TOPIC = "{0}_program_update".format(DOMAIN)
|
||||
SENSOR_UPDATE_TOPIC = "{0}_data_update".format(DOMAIN)
|
||||
ZONE_UPDATE_TOPIC = "{0}_zone_update".format(DOMAIN)
|
||||
PROGRAM_UPDATE_TOPIC = f"{DOMAIN}_program_update"
|
||||
SENSOR_UPDATE_TOPIC = f"{DOMAIN}_data_update"
|
||||
ZONE_UPDATE_TOPIC = f"{DOMAIN}_zone_update"
|
||||
|
||||
CONF_CONTROLLERS = "controllers"
|
||||
CONF_PROGRAM_ID = "program_id"
|
||||
|
|
|
@ -66,7 +66,7 @@ class RecollectWasteSensor(Entity):
|
|||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique ID."""
|
||||
return "{}{}".format(self.client.place_id, self.client.service_id)
|
||||
return f"{self.client.place_id}{self.client.service_id}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
|
|
@ -94,7 +94,7 @@ class RedditSensor(Entity):
|
|||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return "reddit_{}".format(self._subreddit)
|
||||
return f"reddit_{self._subreddit}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
|
|
@ -220,7 +220,7 @@ class PublicTransportData:
|
|||
and due_at_time is not None
|
||||
and route is not None
|
||||
):
|
||||
due_at = "{} {}".format(due_at_date, due_at_time)
|
||||
due_at = f"{due_at_date} {due_at_time}"
|
||||
|
||||
departure_data = {
|
||||
ATTR_DUE_IN: due_in_minutes(due_at),
|
||||
|
|
|
@ -87,13 +87,13 @@ def _create_instance(
|
|||
component.add_entities([entity])
|
||||
hass.services.register(
|
||||
DOMAIN,
|
||||
"{}_create_task".format(account_name),
|
||||
f"{account_name}_create_task",
|
||||
entity.create_task,
|
||||
schema=SERVICE_SCHEMA_CREATE_TASK,
|
||||
)
|
||||
hass.services.register(
|
||||
DOMAIN,
|
||||
"{}_complete_task".format(account_name),
|
||||
f"{account_name}_complete_task",
|
||||
entity.complete_task,
|
||||
schema=SERVICE_SCHEMA_COMPLETE_TASK,
|
||||
)
|
||||
|
@ -137,7 +137,7 @@ def _register_new_account(
|
|||
configurator.request_done(request_id)
|
||||
|
||||
request_id = configurator.async_request_config(
|
||||
"{} - {}".format(DOMAIN, account_name),
|
||||
f"{DOMAIN} - {account_name}",
|
||||
callback=register_account_callback,
|
||||
description="You need to log in to Remember The Milk to"
|
||||
+ "connect your account. \n\n"
|
||||
|
|
|
@ -239,7 +239,7 @@ class PrinterAPI:
|
|||
info["name"] = printer.slug
|
||||
info["printer_name"] = self.conf_name
|
||||
|
||||
known = "{}-{}".format(printer.slug, sensor_type)
|
||||
known = f"{printer.slug}-{sensor_type}"
|
||||
if known in self._known_entities:
|
||||
continue
|
||||
|
||||
|
|
|
@ -300,7 +300,7 @@ class ToggleRflinkLight(SwitchableRflinkDevice, Light):
|
|||
@property
|
||||
def entity_id(self):
|
||||
"""Return entity id."""
|
||||
return "light.{}".format(self.name)
|
||||
return f"light.{self.name}"
|
||||
|
||||
def _handle_event(self, event):
|
||||
"""Adjust state if Rflink picks up a remote command for this device."""
|
||||
|
|
|
@ -106,7 +106,7 @@ def setup(hass, config):
|
|||
slugify(event.device.id_string.lower()),
|
||||
event.device.__class__.__name__,
|
||||
event.device.subtype,
|
||||
"".join("{0:02x}".format(x) for x in event.data),
|
||||
"".join(f"{x:02x}" for x in event.data),
|
||||
)
|
||||
|
||||
# Callback to HA registered components.
|
||||
|
@ -270,7 +270,7 @@ def get_new_device(event, config, device):
|
|||
if not config[ATTR_AUTOMATIC_ADD]:
|
||||
return
|
||||
|
||||
pkt_id = "".join("{0:02x}".format(x) for x in event.data)
|
||||
pkt_id = "".join(f"{x:02x}" for x in event.data)
|
||||
_LOGGER.debug(
|
||||
"Automatic add %s rfxtrx device (Class: %s Sub: %s Packet_id: %s)",
|
||||
device_id,
|
||||
|
|
|
@ -116,7 +116,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
poss_id = slugify(poss_dev.event.device.id_string.lower())
|
||||
_LOGGER.debug("Found possible matching device ID: %s", poss_id)
|
||||
|
||||
pkt_id = "".join("{0:02x}".format(x) for x in event.data)
|
||||
pkt_id = "".join(f"{x:02x}" for x in event.data)
|
||||
sensor = RfxtrxBinarySensor(event, pkt_id)
|
||||
sensor.hass = hass
|
||||
rfxtrx.RFX_DEVICES[device_id] = sensor
|
||||
|
|
|
@ -98,7 +98,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
if not config[CONF_AUTOMATIC_ADD]:
|
||||
return
|
||||
|
||||
pkt_id = "".join("{0:02x}".format(x) for x in event.data)
|
||||
pkt_id = "".join(f"{x:02x}" for x in event.data)
|
||||
_LOGGER.info("Automatic add rfxtrx.sensor: %s", pkt_id)
|
||||
|
||||
data_type = ""
|
||||
|
@ -141,7 +141,7 @@ class RfxtrxSensor(Entity):
|
|||
@property
|
||||
def name(self):
|
||||
"""Get the name of the sensor."""
|
||||
return "{} {}".format(self._name, self.data_type)
|
||||
return f"{self._name} {self.data_type}"
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
|
|
|
@ -73,7 +73,7 @@ class RingBinarySensor(BinarySensorDevice):
|
|||
)
|
||||
self._device_class = SENSOR_TYPES.get(self._sensor_type)[2]
|
||||
self._state = None
|
||||
self._unique_id = "{}-{}".format(self._data.id, self._sensor_type)
|
||||
self._unique_id = f"{self._data.id}-{self._sensor_type}"
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -56,7 +56,7 @@ class RingLight(Light):
|
|||
@property
|
||||
def name(self):
|
||||
"""Name of the light."""
|
||||
return "{} light".format(self._device.name)
|
||||
return f"{self._device.name} light"
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
|
|
|
@ -121,7 +121,7 @@ class RingSensor(Entity):
|
|||
)
|
||||
self._state = None
|
||||
self._tz = str(hass.config.time_zone)
|
||||
self._unique_id = "{}-{}".format(self._data.id, self._sensor_type)
|
||||
self._unique_id = f"{self._data.id}-{self._sensor_type}"
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
|
|
|
@ -38,7 +38,7 @@ class BaseRingSwitch(SwitchDevice):
|
|||
"""Initialize the switch."""
|
||||
self._device = device
|
||||
self._device_type = device_type
|
||||
self._unique_id = "{}-{}".format(self._device.id, self._device_type)
|
||||
self._unique_id = f"{self._device.id}-{self._device_type}"
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
|
@ -53,7 +53,7 @@ class BaseRingSwitch(SwitchDevice):
|
|||
@property
|
||||
def name(self):
|
||||
"""Name of the device."""
|
||||
return "{} {}".format(self._device.name, self._device_type)
|
||||
return f"{self._device.name} {self._device_type}"
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
|
|
|
@ -78,7 +78,7 @@ def scan_for_rokus(hass):
|
|||
"Name: {0}<br />Host: {1}<br />".format(
|
||||
r_info.userdevicename
|
||||
if r_info.userdevicename
|
||||
else "{} {}".format(r_info.modelname, r_info.serial_num),
|
||||
else f"{r_info.modelname} {r_info.serial_num}",
|
||||
roku.host,
|
||||
)
|
||||
)
|
||||
|
|
|
@ -92,7 +92,7 @@ class RokuDevice(MediaPlayerDevice):
|
|||
"""Return the name of the device."""
|
||||
if self._device_info.user_device_name:
|
||||
return self._device_info.user_device_name
|
||||
return "Roku {}".format(self._device_info.serial_num)
|
||||
return f"Roku {self._device_info.serial_num}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
|
|
@ -36,7 +36,7 @@ class RokuRemote(remote.RemoteDevice):
|
|||
"""Return the name of the device."""
|
||||
if self._device_info.user_device_name:
|
||||
return self._device_info.user_device_name
|
||||
return "Roku {}".format(self._device_info.serial_num)
|
||||
return f"Roku {self._device_info.serial_num}"
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
|
|
|
@ -327,7 +327,7 @@ class RoombaVacuum(VacuumDevice):
|
|||
pos_y = pos_state.get("point", {}).get("y")
|
||||
theta = pos_state.get("theta")
|
||||
if all(item is not None for item in [pos_x, pos_y, theta]):
|
||||
position = "({}, {}, {})".format(pos_x, pos_y, theta)
|
||||
position = f"({pos_x}, {pos_y}, {theta})"
|
||||
self._state_attrs[ATTR_POSITION] = position
|
||||
|
||||
# Not all Roombas have a bin full sensor
|
||||
|
|
|
@ -104,7 +104,7 @@ def _update_route53(
|
|||
{
|
||||
"Action": "UPSERT",
|
||||
"ResourceRecordSet": {
|
||||
"Name": "{}.{}".format(record, domain),
|
||||
"Name": f"{record}.{domain}",
|
||||
"Type": "A",
|
||||
"TTL": ttl,
|
||||
"ResourceRecords": [{"Value": ipaddress}],
|
||||
|
|
|
@ -96,7 +96,7 @@ class RovaSensor(Entity):
|
|||
@property
|
||||
def name(self):
|
||||
"""Return the name."""
|
||||
return "{}_{}".format(self.platform_name, self.sensor_key)
|
||||
return f"{self.platform_name}_{self.sensor_key}"
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
|
|
@ -79,7 +79,7 @@ class RTorrentSensor(Entity):
|
|||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return "{} {}".format(self.client_name, self._name)
|
||||
return f"{self.client_name} {self._name}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
|
|
@ -42,7 +42,7 @@ class SabnzbdSensor(Entity):
|
|||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return "{} {}".format(self._client_name, self._name)
|
||||
return f"{self._client_name} {self._name}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
|
|
@ -84,7 +84,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
tv_name = discovery_info.get("name")
|
||||
model = discovery_info.get("model_name")
|
||||
host = discovery_info.get("host")
|
||||
name = "{} ({})".format(tv_name, model)
|
||||
name = f"{tv_name} ({model})"
|
||||
port = DEFAULT_PORT
|
||||
timeout = DEFAULT_TIMEOUT
|
||||
mac = None
|
||||
|
|
|
@ -77,11 +77,11 @@ class SCSGate:
|
|||
"""Handle a messages seen on the bus."""
|
||||
from scsgate.messages import StateMessage, ScenarioTriggeredMessage
|
||||
|
||||
self._logger.debug("Received message {}".format(message))
|
||||
self._logger.debug(f"Received message {message}")
|
||||
if not isinstance(message, StateMessage) and not isinstance(
|
||||
message, ScenarioTriggeredMessage
|
||||
):
|
||||
msg = "Ignored message {} - not relevant type".format(message)
|
||||
msg = f"Ignored message {message} - not relevant type"
|
||||
self._logger.debug(msg)
|
||||
return
|
||||
|
||||
|
@ -97,7 +97,7 @@ class SCSGate:
|
|||
try:
|
||||
self._devices[message.entity].process_event(message)
|
||||
except Exception as exception: # pylint: disable=broad-except
|
||||
msg = "Exception while processing event: {}".format(exception)
|
||||
msg = f"Exception while processing event: {exception}"
|
||||
self._logger.error(msg)
|
||||
else:
|
||||
self._logger.info(
|
||||
|
|
|
@ -80,7 +80,7 @@ class Sense(Entity):
|
|||
def __init__(self, data, name, sensor_type, is_production, update_call):
|
||||
"""Initialize the Sense sensor."""
|
||||
name_type = PRODUCTION_NAME if is_production else CONSUMPTION_NAME
|
||||
self._name = "{} {}".format(name, name_type)
|
||||
self._name = f"{name} {name_type}"
|
||||
self._data = data
|
||||
self._sensor_type = sensor_type
|
||||
self.update_sensor = update_call
|
||||
|
|
|
@ -51,7 +51,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
if config.get(CONF_NAME) is not None:
|
||||
name = "{} PM{}".format(config.get(CONF_NAME), pmname)
|
||||
else:
|
||||
name = "PM{}".format(pmname)
|
||||
name = f"PM{pmname}"
|
||||
dev.append(ParticulateMatterSensor(coll, name, pmname))
|
||||
|
||||
add_entities(dev)
|
||||
|
|
|
@ -120,7 +120,7 @@ class SeventeenTrackSummarySensor(Entity):
|
|||
@property
|
||||
def name(self):
|
||||
"""Return the name."""
|
||||
return "Seventeentrack Packages {0}".format(self._status)
|
||||
return f"Seventeentrack Packages {self._status}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
@ -203,7 +203,7 @@ class SeventeenTrackPackageSensor(Entity):
|
|||
name = self._friendly_name
|
||||
if not name:
|
||||
name = self._tracking_number
|
||||
return "Seventeentrack Package: {0}".format(name)
|
||||
return f"Seventeentrack Package: {name}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
|
|
@ -69,10 +69,7 @@ def setup(hass, config):
|
|||
if state.attributes:
|
||||
for attribute, data in state.attributes.items():
|
||||
mqttc.publish(
|
||||
"/{}/{}".format(topic, attribute),
|
||||
str(data),
|
||||
qos=0,
|
||||
retain=False,
|
||||
f"/{topic}/{attribute}", str(data), qos=0, retain=False
|
||||
)
|
||||
except RuntimeError:
|
||||
pass
|
||||
|
|
|
@ -196,7 +196,7 @@ class AddItemIntent(intent.IntentHandler):
|
|||
intent_obj.hass.data[DOMAIN].async_add(item)
|
||||
|
||||
response = intent_obj.create_response()
|
||||
response.async_set_speech("I've added {} to your shopping list".format(item))
|
||||
response.async_set_speech(f"I've added {item} to your shopping list")
|
||||
intent_obj.hass.bus.async_fire(EVENT)
|
||||
return response
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ class SigfoxAPI:
|
|||
"""Get the device_id of each device registered."""
|
||||
devices = []
|
||||
for unique_type in device_types:
|
||||
location_url = "devicetypes/{}/devices".format(unique_type)
|
||||
location_url = f"devicetypes/{unique_type}/devices"
|
||||
url = urljoin(API_URL, location_url)
|
||||
response = requests.get(url, auth=self._auth, timeout=10)
|
||||
devices_data = json.loads(response.text)["data"]
|
||||
|
@ -117,12 +117,12 @@ class SigfoxDevice(Entity):
|
|||
self._device_id = device_id
|
||||
self._auth = auth
|
||||
self._message_data = {}
|
||||
self._name = "{}_{}".format(name, device_id)
|
||||
self._name = f"{name}_{device_id}"
|
||||
self._state = None
|
||||
|
||||
def get_last_message(self):
|
||||
"""Return the last message from a device."""
|
||||
device_url = "devices/{}/messages?limit=1".format(self._device_id)
|
||||
device_url = f"devices/{self._device_id}/messages?limit=1"
|
||||
url = urljoin(API_URL, device_url)
|
||||
response = requests.get(url, auth=self._auth, timeout=10)
|
||||
data = json.loads(response.text)["data"][0]
|
||||
|
|
|
@ -34,7 +34,7 @@ class SkyHubDeviceScanner(DeviceScanner):
|
|||
_LOGGER.info("Initialising Sky Hub")
|
||||
self.host = config.get(CONF_HOST, "192.168.1.254")
|
||||
self.last_results = {}
|
||||
self.url = "http://{}/".format(self.host)
|
||||
self.url = f"http://{self.host}/"
|
||||
|
||||
# Test the router is accessible
|
||||
data = _get_skyhub_data(self.url)
|
||||
|
|
|
@ -57,7 +57,7 @@ class SkybellCamera(SkybellDevice, Camera):
|
|||
SkybellDevice.__init__(self, device)
|
||||
Camera.__init__(self)
|
||||
if name is not None:
|
||||
self._name = "{} {}".format(self._device.name, name)
|
||||
self._name = f"{self._device.name} {name}"
|
||||
else:
|
||||
self._name = self._device.name
|
||||
self._url = None
|
||||
|
|
|
@ -50,7 +50,7 @@ def _check_sensor_schema(conf):
|
|||
sensor,
|
||||
)
|
||||
elif sensor not in valid:
|
||||
raise vol.Invalid("{} does not exist".format(sensor))
|
||||
raise vol.Invalid(f"{sensor} does not exist")
|
||||
return conf
|
||||
|
||||
|
||||
|
@ -217,7 +217,7 @@ class SMAsensor(Entity):
|
|||
update = False
|
||||
|
||||
for sens in self._sub_sensors: # Can be remove from 0.99
|
||||
newval = "{} {}".format(sens.value, sens.unit)
|
||||
newval = f"{sens.value} {sens.unit}"
|
||||
if self._attr[sens.name] != newval:
|
||||
update = True
|
||||
self._attr[sens.name] = newval
|
||||
|
@ -231,4 +231,4 @@ class SMAsensor(Entity):
|
|||
@property
|
||||
def unique_id(self):
|
||||
"""Return a unique identifier for this sensor."""
|
||||
return "sma-{}-{}".format(self._sensor.key, self._sensor.name)
|
||||
return f"sma-{self._sensor.key}-{self._sensor.name}"
|
||||
|
|
|
@ -139,7 +139,7 @@ class SmappeeSensor(Entity):
|
|||
else:
|
||||
location_name = "Local"
|
||||
|
||||
return "{} {} {}".format(SENSOR_PREFIX, location_name, self._name)
|
||||
return f"{SENSOR_PREFIX} {location_name} {self._name}"
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
|
|
@ -66,12 +66,12 @@ class SmartThingsBinarySensor(SmartThingsEntity, BinarySensorDevice):
|
|||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the binary sensor."""
|
||||
return "{} {}".format(self._device.label, self._attribute)
|
||||
return f"{self._device.label} {self._attribute}"
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique ID."""
|
||||
return "{}.{}".format(self._device.device_id, self._attribute)
|
||||
return f"{self._device.device_id}.{self._attribute}"
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
|
|
|
@ -283,12 +283,12 @@ class SmartThingsSensor(SmartThingsEntity):
|
|||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the binary sensor."""
|
||||
return "{} {}".format(self._device.label, self._name)
|
||||
return f"{self._device.label} {self._name}"
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique ID."""
|
||||
return "{}.{}".format(self._device.device_id, self._attribute)
|
||||
return f"{self._device.device_id}.{self._attribute}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
|
|
@ -112,7 +112,7 @@ def _get_app_template(hass: HomeAssistantType):
|
|||
cloudhook_url = hass.data[DOMAIN][CONF_CLOUDHOOK_URL]
|
||||
if cloudhook_url is not None:
|
||||
endpoint = "via Nabu Casa"
|
||||
description = "{} {}".format(hass.config.location_name, endpoint)
|
||||
description = f"{hass.config.location_name} {endpoint}"
|
||||
|
||||
return {
|
||||
"app_name": APP_NAME_PREFIX + str(uuid4()),
|
||||
|
|
|
@ -69,9 +69,7 @@ class BoostSensor(SmartyBinarySensor):
|
|||
|
||||
def __init__(self, name, smarty):
|
||||
"""Alarm Sensor Init."""
|
||||
super().__init__(
|
||||
name="{} Boost State".format(name), device_class=None, smarty=smarty
|
||||
)
|
||||
super().__init__(name=f"{name} Boost State", device_class=None, smarty=smarty)
|
||||
|
||||
def update(self) -> None:
|
||||
"""Update state."""
|
||||
|
@ -84,9 +82,7 @@ class AlarmSensor(SmartyBinarySensor):
|
|||
|
||||
def __init__(self, name, smarty):
|
||||
"""Alarm Sensor Init."""
|
||||
super().__init__(
|
||||
name="{} Alarm".format(name), device_class="problem", smarty=smarty
|
||||
)
|
||||
super().__init__(name=f"{name} Alarm", device_class="problem", smarty=smarty)
|
||||
|
||||
def update(self) -> None:
|
||||
"""Update state."""
|
||||
|
@ -99,9 +95,7 @@ class WarningSensor(SmartyBinarySensor):
|
|||
|
||||
def __init__(self, name, smarty):
|
||||
"""Warning Sensor Init."""
|
||||
super().__init__(
|
||||
name="{} Warning".format(name), device_class="problem", smarty=smarty
|
||||
)
|
||||
super().__init__(name=f"{name} Warning", device_class="problem", smarty=smarty)
|
||||
|
||||
def update(self) -> None:
|
||||
"""Update state."""
|
||||
|
|
|
@ -88,7 +88,7 @@ class SupplyAirTemperatureSensor(SmartySensor):
|
|||
def __init__(self, name, smarty):
|
||||
"""Supply Air Temperature Init."""
|
||||
super().__init__(
|
||||
name="{} Supply Air Temperature".format(name),
|
||||
name=f"{name} Supply Air Temperature",
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
unit_of_measurement=TEMP_CELSIUS,
|
||||
smarty=smarty,
|
||||
|
@ -106,7 +106,7 @@ class ExtractAirTemperatureSensor(SmartySensor):
|
|||
def __init__(self, name, smarty):
|
||||
"""Supply Air Temperature Init."""
|
||||
super().__init__(
|
||||
name="{} Extract Air Temperature".format(name),
|
||||
name=f"{name} Extract Air Temperature",
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
unit_of_measurement=TEMP_CELSIUS,
|
||||
smarty=smarty,
|
||||
|
@ -124,7 +124,7 @@ class OutdoorAirTemperatureSensor(SmartySensor):
|
|||
def __init__(self, name, smarty):
|
||||
"""Outdoor Air Temperature Init."""
|
||||
super().__init__(
|
||||
name="{} Outdoor Air Temperature".format(name),
|
||||
name=f"{name} Outdoor Air Temperature",
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
unit_of_measurement=TEMP_CELSIUS,
|
||||
smarty=smarty,
|
||||
|
@ -142,7 +142,7 @@ class SupplyFanSpeedSensor(SmartySensor):
|
|||
def __init__(self, name, smarty):
|
||||
"""Supply Fan Speed RPM Init."""
|
||||
super().__init__(
|
||||
name="{} Supply Fan Speed".format(name),
|
||||
name=f"{name} Supply Fan Speed",
|
||||
device_class=None,
|
||||
unit_of_measurement=None,
|
||||
smarty=smarty,
|
||||
|
@ -160,7 +160,7 @@ class ExtractFanSpeedSensor(SmartySensor):
|
|||
def __init__(self, name, smarty):
|
||||
"""Extract Fan Speed RPM Init."""
|
||||
super().__init__(
|
||||
name="{} Extract Fan Speed".format(name),
|
||||
name=f"{name} Extract Fan Speed",
|
||||
device_class=None,
|
||||
unit_of_measurement=None,
|
||||
smarty=smarty,
|
||||
|
@ -178,7 +178,7 @@ class FilterDaysLeftSensor(SmartySensor):
|
|||
def __init__(self, name, smarty):
|
||||
"""Filter Days Left Init."""
|
||||
super().__init__(
|
||||
name="{} Filter Days Left".format(name),
|
||||
name=f"{name} Filter Days Left",
|
||||
device_class=DEVICE_CLASS_TIMESTAMP,
|
||||
unit_of_measurement=None,
|
||||
smarty=smarty,
|
||||
|
|
|
@ -102,7 +102,7 @@ class SmhiWeather(WeatherEntity):
|
|||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique id."""
|
||||
return "{}, {}".format(self._latitude, self._longitude)
|
||||
return f"{self._latitude}, {self._longitude}"
|
||||
|
||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||
async def async_update(self) -> None:
|
||||
|
|
|
@ -182,7 +182,7 @@ class MailNotificationService(BaseNotificationService):
|
|||
msg["Subject"] = subject
|
||||
msg["To"] = ",".join(self.recipients)
|
||||
if self._sender_name:
|
||||
msg["From"] = "{} <{}>".format(self._sender_name, self._sender)
|
||||
msg["From"] = f"{self._sender_name} <{self._sender}>"
|
||||
else:
|
||||
msg["From"] = self._sender
|
||||
msg["X-Mailer"] = "HomeAssistant"
|
||||
|
@ -225,18 +225,18 @@ def _build_multipart_msg(message, images):
|
|||
msg.attach(msg_alt)
|
||||
body_txt = MIMEText(message)
|
||||
msg_alt.attach(body_txt)
|
||||
body_text = ["<p>{}</p><br>".format(message)]
|
||||
body_text = [f"<p>{message}</p><br>"]
|
||||
|
||||
for atch_num, atch_name in enumerate(images):
|
||||
cid = "image{}".format(atch_num)
|
||||
body_text.append('<img src="cid:{}"><br>'.format(cid))
|
||||
cid = f"image{atch_num}"
|
||||
body_text.append(f'<img src="cid:{cid}"><br>')
|
||||
try:
|
||||
with open(atch_name, "rb") as attachment_file:
|
||||
file_bytes = attachment_file.read()
|
||||
try:
|
||||
attachment = MIMEImage(file_bytes)
|
||||
msg.attach(attachment)
|
||||
attachment.add_header("Content-ID", "<{}>".format(cid))
|
||||
attachment.add_header("Content-ID", f"<{cid}>")
|
||||
except TypeError:
|
||||
_LOGGER.warning(
|
||||
"Attachment %s has an unknown MIME type. "
|
||||
|
@ -271,7 +271,7 @@ def _build_html_msg(text, html, images):
|
|||
with open(atch_name, "rb") as attachment_file:
|
||||
attachment = MIMEImage(attachment_file.read(), filename=name)
|
||||
msg.attach(attachment)
|
||||
attachment.add_header("Content-ID", "<{}>".format(name))
|
||||
attachment.add_header("Content-ID", f"<{name}>")
|
||||
except FileNotFoundError:
|
||||
_LOGGER.warning(
|
||||
"Attachment %s [#%s] not found. Skipping", atch_name, atch_num
|
||||
|
|
|
@ -98,7 +98,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
return
|
||||
|
||||
# Note: Host part is needed, when using multiple snapservers
|
||||
hpid = "{}:{}".format(host, port)
|
||||
hpid = f"{host}:{port}"
|
||||
|
||||
groups = [SnapcastGroupDevice(group, hpid) for group in server.groups]
|
||||
clients = [SnapcastClientDevice(client, hpid) for client in server.clients]
|
||||
|
@ -114,7 +114,7 @@ class SnapcastGroupDevice(MediaPlayerDevice):
|
|||
"""Initialize the Snapcast group device."""
|
||||
group.set_callback(self.schedule_update_ha_state)
|
||||
self._group = group
|
||||
self._uid = "{}{}_{}".format(GROUP_PREFIX, uid_part, self._group.identifier)
|
||||
self._uid = f"{GROUP_PREFIX}{uid_part}_{self._group.identifier}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
@ -133,7 +133,7 @@ class SnapcastGroupDevice(MediaPlayerDevice):
|
|||
@property
|
||||
def name(self):
|
||||
"""Return the name of the device."""
|
||||
return "{}{}".format(GROUP_PREFIX, self._group.identifier)
|
||||
return f"{GROUP_PREFIX}{self._group.identifier}"
|
||||
|
||||
@property
|
||||
def source(self):
|
||||
|
@ -163,7 +163,7 @@ class SnapcastGroupDevice(MediaPlayerDevice):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
name = "{} {}".format(self._group.friendly_name, GROUP_SUFFIX)
|
||||
name = f"{self._group.friendly_name} {GROUP_SUFFIX}"
|
||||
return {"friendly_name": name}
|
||||
|
||||
@property
|
||||
|
@ -204,7 +204,7 @@ class SnapcastClientDevice(MediaPlayerDevice):
|
|||
"""Initialize the Snapcast client device."""
|
||||
client.set_callback(self.schedule_update_ha_state)
|
||||
self._client = client
|
||||
self._uid = "{}{}_{}".format(CLIENT_PREFIX, uid_part, self._client.identifier)
|
||||
self._uid = f"{CLIENT_PREFIX}{uid_part}_{self._client.identifier}"
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
|
@ -223,7 +223,7 @@ class SnapcastClientDevice(MediaPlayerDevice):
|
|||
@property
|
||||
def name(self):
|
||||
"""Return the name of the device."""
|
||||
return "{}{}".format(CLIENT_PREFIX, self._client.identifier)
|
||||
return f"{CLIENT_PREFIX}{self._client.identifier}"
|
||||
|
||||
@property
|
||||
def source(self):
|
||||
|
@ -260,7 +260,7 @@ class SnapcastClientDevice(MediaPlayerDevice):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
name = "{} {}".format(self._client.friendly_name, CLIENT_SUFFIX)
|
||||
name = f"{self._client.friendly_name} {CLIENT_SUFFIX}"
|
||||
return {"friendly_name": name}
|
||||
|
||||
@property
|
||||
|
|
|
@ -67,7 +67,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
platform_name = config[CONF_NAME]
|
||||
|
||||
# Create new SolarEdge object to retrieve data
|
||||
api = SolarEdge("http://{}/".format(ip_address))
|
||||
api = SolarEdge(f"http://{ip_address}/")
|
||||
|
||||
# Check if api can be reached and site is active
|
||||
try:
|
||||
|
|
|
@ -35,7 +35,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
idx, unit = solax.INVERTER_SENSORS[sensor]
|
||||
if unit == "C":
|
||||
unit = TEMP_CELSIUS
|
||||
uid = "{}-{}".format(serial, idx)
|
||||
uid = f"{serial}-{idx}"
|
||||
devices.append(Inverter(uid, serial, sensor, unit))
|
||||
endpoint.sensors = devices
|
||||
async_add_entities(devices)
|
||||
|
@ -97,7 +97,7 @@ class Inverter(Entity):
|
|||
@property
|
||||
def name(self):
|
||||
"""Name of this inverter attribute."""
|
||||
return "Solax {} {}".format(self.serial, self.key)
|
||||
return f"Solax {self.serial} {self.key}"
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
|
|
|
@ -73,7 +73,7 @@ class SomfyFlowHandler(config_entries.ConfigFlow):
|
|||
|
||||
client_id = self.hass.data[DOMAIN][CLIENT_ID]
|
||||
client_secret = self.hass.data[DOMAIN][CLIENT_SECRET]
|
||||
redirect_uri = "{}{}".format(self.hass.config.api.base_url, AUTH_CALLBACK_PATH)
|
||||
redirect_uri = f"{self.hass.config.api.base_url}{AUTH_CALLBACK_PATH}"
|
||||
api = SomfyApi(client_id, client_secret, redirect_uri)
|
||||
|
||||
self.hass.http.register_view(SomfyAuthCallbackView())
|
||||
|
@ -95,7 +95,7 @@ class SomfyFlowHandler(config_entries.ConfigFlow):
|
|||
code = self.code
|
||||
from pymfy.api.somfy_api import SomfyApi
|
||||
|
||||
redirect_uri = "{}{}".format(self.hass.config.api.base_url, AUTH_CALLBACK_PATH)
|
||||
redirect_uri = f"{self.hass.config.api.base_url}{AUTH_CALLBACK_PATH}"
|
||||
api = SomfyApi(client_id, client_secret, redirect_uri)
|
||||
token = await self.hass.async_add_executor_job(api.request_token, None, code)
|
||||
_LOGGER.info("Successfully authenticated Somfy")
|
||||
|
|
|
@ -606,7 +606,7 @@ class SonosEntity(MediaPlayerDevice):
|
|||
# media_artist = "Station - Artist - Title"
|
||||
# detect this case and trim from the front of
|
||||
# media_artist for cosmetics
|
||||
trim = "{title} - ".format(title=self._media_title)
|
||||
trim = f"{self._media_title} - "
|
||||
chars = min(len(self._media_artist), len(trim))
|
||||
|
||||
if self._media_artist[:chars].upper() == trim[:chars].upper():
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
"""Consts used by Speedtest.net."""
|
||||
|
||||
DOMAIN = "speedtestdotnet"
|
||||
DATA_UPDATED = "{}_data_updated".format(DOMAIN)
|
||||
DATA_UPDATED = f"{DOMAIN}_data_updated"
|
||||
|
||||
SENSOR_TYPES = {
|
||||
"ping": ["Ping", "ms"],
|
||||
|
|
|
@ -29,7 +29,7 @@ CONF_DAYS = "days"
|
|||
DEFAULT_DAYS = 1
|
||||
NAME = "spotcrime"
|
||||
|
||||
EVENT_INCIDENT = "{}_incident".format(NAME)
|
||||
EVENT_INCIDENT = f"{NAME}_incident"
|
||||
|
||||
SCAN_INTERVAL = timedelta(minutes=30)
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
"""Set up the Spotify platform."""
|
||||
import spotipy.oauth2
|
||||
|
||||
callback_url = "{}{}".format(hass.config.api.base_url, AUTH_CALLBACK_PATH)
|
||||
callback_url = f"{hass.config.api.base_url}{AUTH_CALLBACK_PATH}"
|
||||
cache = config.get(CONF_CACHE_PATH, hass.config.path(DEFAULT_CACHE_PATH))
|
||||
oauth = spotipy.oauth2.SpotifyOAuth(
|
||||
config.get(CONF_CLIENT_ID),
|
||||
|
|
|
@ -208,7 +208,7 @@ class LogitechMediaServer:
|
|||
if self._username is None
|
||||
else aiohttp.BasicAuth(self._username, self._password)
|
||||
)
|
||||
url = "http://{}:{}/jsonrpc.js".format(self.host, self.port)
|
||||
url = f"http://{self.host}:{self.port}/jsonrpc.js"
|
||||
data = json.dumps(
|
||||
{"id": "1", "method": "slim.request", "params": [player, command]}
|
||||
)
|
||||
|
@ -288,9 +288,7 @@ class SqueezeBoxDevice(MediaPlayerDevice):
|
|||
async def async_update(self):
|
||||
"""Retrieve the current state of the player."""
|
||||
tags = "adKl"
|
||||
response = await self.async_query(
|
||||
"status", "-", "1", "tags:{tags}".format(tags=tags)
|
||||
)
|
||||
response = await self.async_query("status", "-", "1", f"tags:{tags}")
|
||||
|
||||
if response is False:
|
||||
return
|
||||
|
|
|
@ -87,7 +87,7 @@ class SrpEnergy(Entity):
|
|||
if self._state is None:
|
||||
return None
|
||||
|
||||
return "{0:.2f}".format(self._state)
|
||||
return f"{self._state:.2f}"
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -86,7 +86,7 @@ class StartcaSensor(Entity):
|
|||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return "{} {}".format(self.client_name, self._name)
|
||||
return f"{self.client_name} {self._name}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
|
|
@ -80,7 +80,7 @@ class SteamSensor(Entity):
|
|||
@property
|
||||
def entity_id(self):
|
||||
"""Return the entity ID."""
|
||||
return "sensor.steam_{}".format(self._account)
|
||||
return f"sensor.steam_{self._account}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
|
|
@ -139,7 +139,7 @@ class StiebelEltron(ClimateDevice):
|
|||
@property
|
||||
def current_humidity(self):
|
||||
"""Return the current humidity."""
|
||||
return float("{0:.1f}".format(self._current_humidity))
|
||||
return float(f"{self._current_humidity:.1f}")
|
||||
|
||||
@property
|
||||
def hvac_modes(self):
|
||||
|
|
|
@ -217,9 +217,7 @@ async def async_handle_record_service(hass, call):
|
|||
|
||||
# Check for file access
|
||||
if not hass.config.is_allowed_path(video_path):
|
||||
raise HomeAssistantError(
|
||||
"Can't write {}, no access to path!".format(video_path)
|
||||
)
|
||||
raise HomeAssistantError(f"Can't write {video_path}, no access to path!")
|
||||
|
||||
# Check for active stream
|
||||
streams = hass.data[DOMAIN][ATTR_STREAMS]
|
||||
|
@ -231,9 +229,7 @@ async def async_handle_record_service(hass, call):
|
|||
# Add recorder
|
||||
recorder = stream.outputs.get("recorder")
|
||||
if recorder:
|
||||
raise HomeAssistantError(
|
||||
"Stream already recording to {}!".format(recorder.video_path)
|
||||
)
|
||||
raise HomeAssistantError(f"Stream already recording to {recorder.video_path}!")
|
||||
|
||||
recorder = stream.add_provider("recorder")
|
||||
recorder.video_path = video_path
|
||||
|
|
|
@ -64,10 +64,7 @@ class M3U8Renderer:
|
|||
@staticmethod
|
||||
def render_preamble(track):
|
||||
"""Render preamble."""
|
||||
return [
|
||||
"#EXT-X-VERSION:3",
|
||||
"#EXT-X-TARGETDURATION:{}".format(track.target_duration),
|
||||
]
|
||||
return ["#EXT-X-VERSION:3", f"#EXT-X-TARGETDURATION:{track.target_duration}"]
|
||||
|
||||
@staticmethod
|
||||
def render_playlist(track, start_time):
|
||||
|
@ -84,7 +81,7 @@ class M3U8Renderer:
|
|||
playlist.extend(
|
||||
[
|
||||
"#EXTINF:{:.04f},".format(float(segment.duration)),
|
||||
"./segment/{}.ts".format(segment.sequence),
|
||||
f"./segment/{segment.sequence}.ts",
|
||||
]
|
||||
)
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ class StreamlabsAwayMode(BinarySensorDevice):
|
|||
@property
|
||||
def name(self):
|
||||
"""Return the name for away mode."""
|
||||
return "{} {}".format(self._location_name, NAME_AWAY_MODE)
|
||||
return f"{self._location_name} {NAME_AWAY_MODE}"
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
|
|
|
@ -79,7 +79,7 @@ class StreamLabsDailyUsage(Entity):
|
|||
@property
|
||||
def name(self):
|
||||
"""Return the name for daily usage."""
|
||||
return "{} {}".format(self._location_name, NAME_DAILY_USAGE)
|
||||
return f"{self._location_name} {NAME_DAILY_USAGE}"
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
@ -107,7 +107,7 @@ class StreamLabsMonthlyUsage(StreamLabsDailyUsage):
|
|||
@property
|
||||
def name(self):
|
||||
"""Return the name for monthly usage."""
|
||||
return "{} {}".format(self._location_name, NAME_MONTHLY_USAGE)
|
||||
return f"{self._location_name} {NAME_MONTHLY_USAGE}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
@ -121,7 +121,7 @@ class StreamLabsYearlyUsage(StreamLabsDailyUsage):
|
|||
@property
|
||||
def name(self):
|
||||
"""Return the name for yearly usage."""
|
||||
return "{} {}".format(self._location_name, NAME_YEARLY_USAGE)
|
||||
return f"{self._location_name} {NAME_YEARLY_USAGE}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
|
|
@ -101,7 +101,7 @@ class SwissHydrologicalDataSensor(Entity):
|
|||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique, friendly identifier for this entity."""
|
||||
return "{0}_{1}".format(self._station, self._condition)
|
||||
return f"{self._station}_{self._condition}"
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
|
|
|
@ -110,7 +110,7 @@ class SwissPublicTransportSensor(Entity):
|
|||
ATTR_DEPARTURE_TIME2: self._opendata.connections[2]["departure"],
|
||||
ATTR_START: self._opendata.from_name,
|
||||
ATTR_TARGET: self._opendata.to_name,
|
||||
ATTR_REMAINING_TIME: "{}".format(self._remaining_time),
|
||||
ATTR_REMAINING_TIME: f"{self._remaining_time}",
|
||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
||||
}
|
||||
return attr
|
||||
|
|
|
@ -74,7 +74,7 @@ class SwisscomDeviceScanner(DeviceScanner):
|
|||
|
||||
def get_swisscom_data(self):
|
||||
"""Retrieve data from Swisscom and return parsed result."""
|
||||
url = "http://{}/ws".format(self.host)
|
||||
url = f"http://{self.host}/ws"
|
||||
headers = {CONTENT_TYPE: "application/x-sah-ws-4-call+json"}
|
||||
data = """
|
||||
{"service":"Devices", "method":"get",
|
||||
|
|
|
@ -65,7 +65,7 @@ class SwitcherControl(SwitchDevice):
|
|||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique ID."""
|
||||
return "{}-{}".format(self._device_data.device_id, self._device_data.mac_addr)
|
||||
return f"{self._device_data.device_id}-{self._device_data.mac_addr}"
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
|
|
|
@ -18,12 +18,10 @@ TONER_COLORS = COLORS
|
|||
TRAYS = range(1, 6)
|
||||
OUTPUT_TRAYS = range(0, 6)
|
||||
DEFAULT_MONITORED_CONDITIONS = []
|
||||
DEFAULT_MONITORED_CONDITIONS.extend(["toner_{}".format(key) for key in TONER_COLORS])
|
||||
DEFAULT_MONITORED_CONDITIONS.extend(["drum_{}".format(key) for key in DRUM_COLORS])
|
||||
DEFAULT_MONITORED_CONDITIONS.extend(["tray_{}".format(key) for key in TRAYS])
|
||||
DEFAULT_MONITORED_CONDITIONS.extend(
|
||||
["output_tray_{}".format(key) for key in OUTPUT_TRAYS]
|
||||
)
|
||||
DEFAULT_MONITORED_CONDITIONS.extend([f"toner_{key}" for key in TONER_COLORS])
|
||||
DEFAULT_MONITORED_CONDITIONS.extend([f"drum_{key}" for key in DRUM_COLORS])
|
||||
DEFAULT_MONITORED_CONDITIONS.extend([f"tray_{key}" for key in TRAYS])
|
||||
DEFAULT_MONITORED_CONDITIONS.extend([f"output_tray_{key}" for key in OUTPUT_TRAYS])
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
|
@ -81,16 +79,16 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
devices = [SyncThruMainSensor(printer, name)]
|
||||
|
||||
for key in supp_toner:
|
||||
if "toner_{}".format(key) in monitored:
|
||||
if f"toner_{key}" in monitored:
|
||||
devices.append(SyncThruTonerSensor(printer, name, key))
|
||||
for key in supp_drum:
|
||||
if "drum_{}".format(key) in monitored:
|
||||
if f"drum_{key}" in monitored:
|
||||
devices.append(SyncThruDrumSensor(printer, name, key))
|
||||
for key in supp_tray:
|
||||
if "tray_{}".format(key) in monitored:
|
||||
if f"tray_{key}" in monitored:
|
||||
devices.append(SyncThruInputTraySensor(printer, name, key))
|
||||
for key in supp_output_tray:
|
||||
if "output_tray_{}".format(key) in monitored:
|
||||
if f"output_tray_{key}" in monitored:
|
||||
devices.append(SyncThruOutputTraySensor(printer, name, key))
|
||||
|
||||
async_add_entities(devices, True)
|
||||
|
@ -173,10 +171,10 @@ class SyncThruTonerSensor(SyncThruSensor):
|
|||
def __init__(self, syncthru, name, color):
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(syncthru, name)
|
||||
self._name = "{} Toner {}".format(name, color)
|
||||
self._name = f"{name} Toner {color}"
|
||||
self._color = color
|
||||
self._unit_of_measurement = "%"
|
||||
self._id_suffix = "_toner_{}".format(color)
|
||||
self._id_suffix = f"_toner_{color}"
|
||||
|
||||
def update(self):
|
||||
"""Get the latest data from SyncThru and update the state."""
|
||||
|
@ -193,10 +191,10 @@ class SyncThruDrumSensor(SyncThruSensor):
|
|||
def __init__(self, syncthru, name, color):
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(syncthru, name)
|
||||
self._name = "{} Drum {}".format(name, color)
|
||||
self._name = f"{name} Drum {color}"
|
||||
self._color = color
|
||||
self._unit_of_measurement = "%"
|
||||
self._id_suffix = "_drum_{}".format(color)
|
||||
self._id_suffix = f"_drum_{color}"
|
||||
|
||||
def update(self):
|
||||
"""Get the latest data from SyncThru and update the state."""
|
||||
|
@ -213,9 +211,9 @@ class SyncThruInputTraySensor(SyncThruSensor):
|
|||
def __init__(self, syncthru, name, number):
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(syncthru, name)
|
||||
self._name = "{} Tray {}".format(name, number)
|
||||
self._name = f"{name} Tray {number}"
|
||||
self._number = number
|
||||
self._id_suffix = "_tray_{}".format(number)
|
||||
self._id_suffix = f"_tray_{number}"
|
||||
|
||||
def update(self):
|
||||
"""Get the latest data from SyncThru and update the state."""
|
||||
|
@ -234,9 +232,9 @@ class SyncThruOutputTraySensor(SyncThruSensor):
|
|||
def __init__(self, syncthru, name, number):
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(syncthru, name)
|
||||
self._name = "{} Output Tray {}".format(name, number)
|
||||
self._name = f"{name} Output Tray {number}"
|
||||
self._number = number
|
||||
self._id_suffix = "_output_tray_{}".format(number)
|
||||
self._id_suffix = f"_output_tray_{number}"
|
||||
|
||||
def update(self):
|
||||
"""Get the latest data from SyncThru and update the state."""
|
||||
|
|
|
@ -184,7 +184,7 @@ class SynoNasSensor(Entity):
|
|||
def name(self):
|
||||
"""Return the name of the sensor, if any."""
|
||||
if self.monitor_device is not None:
|
||||
return "{} ({})".format(self.var_name, self.monitor_device)
|
||||
return f"{self.var_name} ({self.monitor_device})"
|
||||
return self.var_name
|
||||
|
||||
@property
|
||||
|
|
|
@ -86,7 +86,7 @@ class SytadinSensor(Entity):
|
|||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return "{} {}".format(self._name, self._option)
|
||||
return f"{self._name} {self._option}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue