Use dict literals (#33658)

This commit is contained in:
springstan 2020-04-04 22:31:56 +02:00 committed by GitHub
parent 541e30d155
commit 0d95eff21d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 33 additions and 33 deletions

View File

@ -137,7 +137,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
vol.Optional(CONF_ADB_SERVER_IP): cv.string, vol.Optional(CONF_ADB_SERVER_IP): cv.string,
vol.Optional(CONF_ADB_SERVER_PORT, default=DEFAULT_ADB_SERVER_PORT): cv.port, vol.Optional(CONF_ADB_SERVER_PORT, default=DEFAULT_ADB_SERVER_PORT): cv.port,
vol.Optional(CONF_GET_SOURCES, default=DEFAULT_GET_SOURCES): cv.boolean, vol.Optional(CONF_GET_SOURCES, default=DEFAULT_GET_SOURCES): cv.boolean,
vol.Optional(CONF_APPS, default=dict()): vol.Schema( vol.Optional(CONF_APPS, default={}): vol.Schema(
{cv.string: vol.Any(cv.string, None)} {cv.string: vol.Any(cv.string, None)}
), ),
vol.Optional(CONF_TURN_ON_COMMAND): cv.string, vol.Optional(CONF_TURN_ON_COMMAND): cv.string,
@ -327,7 +327,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
target_device.adb_push(local_path, device_path) target_device.adb_push(local_path, device_path)
hass.services.register( hass.services.register(
ANDROIDTV_DOMAIN, SERVICE_UPLOAD, service_upload, schema=SERVICE_UPLOAD_SCHEMA, ANDROIDTV_DOMAIN, SERVICE_UPLOAD, service_upload, schema=SERVICE_UPLOAD_SCHEMA
) )

View File

@ -58,7 +58,7 @@ class EditSceneConfigView(EditIdBasedConfigView):
elif cur_value[CONF_ID] == config_key: elif cur_value[CONF_ID] == config_key:
break break
else: else:
cur_value = dict() cur_value = {}
cur_value[CONF_ID] = config_key cur_value[CONF_ID] = config_key
index = len(data) index = len(data)
data.append(cur_value) data.append(cur_value)

View File

@ -170,7 +170,7 @@ def async_setup_scanner_platform(
try: try:
extra_attributes = await scanner.async_get_extra_attributes(mac) extra_attributes = await scanner.async_get_extra_attributes(mac)
except NotImplementedError: except NotImplementedError:
extra_attributes = dict() extra_attributes = {}
kwargs = { kwargs = {
"mac": mac, "mac": mac,

View File

@ -165,7 +165,7 @@ class DHTClient:
self.adafruit_dht = adafruit_dht self.adafruit_dht = adafruit_dht
self.sensor = sensor self.sensor = sensor
self.pin = pin self.pin = pin
self.data = dict() self.data = {}
@Throttle(MIN_TIME_BETWEEN_UPDATES) @Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self): def update(self):

View File

@ -184,7 +184,7 @@ class EcobeeWeather(WeatherEntity):
def _process_forecast(json): def _process_forecast(json):
"""Process a single ecobee API forecast to return expected values.""" """Process a single ecobee API forecast to return expected values."""
forecast = dict() forecast = {}
try: try:
forecast[ATTR_FORECAST_TIME] = datetime.strptime( forecast[ATTR_FORECAST_TIME] = datetime.strptime(
json["dateTime"], "%Y-%m-%d %H:%M:%S" json["dateTime"], "%Y-%m-%d %H:%M:%S"

View File

@ -228,7 +228,7 @@ class Config:
self.entities = conf.get(CONF_ENTITIES, {}) self.entities = conf.get(CONF_ENTITIES, {})
self._entities_with_hidden_attr_in_config = dict() self._entities_with_hidden_attr_in_config = {}
for entity_id in self.entities: for entity_id in self.entities:
hidden_value = self.entities[entity_id].get(CONF_ENTITY_HIDDEN, None) hidden_value = self.entities[entity_id].get(CONF_ENTITY_HIDDEN, None)
if hidden_value is not None: if hidden_value is not None:

View File

@ -108,7 +108,7 @@ class BanLogParser:
"""Initialize the parser.""" """Initialize the parser."""
self.log_file = log_file self.log_file = log_file
self.data = list() self.data = list()
self.ip_regex = dict() self.ip_regex = {}
def read_log(self, jail): def read_log(self, jail):
"""Read the fail2ban log and find entries for jail.""" """Read the fail2ban log and find entries for jail."""

View File

@ -64,7 +64,7 @@ async def async_setup(hass, config):
value2 = call.data.get(ATTR_VALUE2) value2 = call.data.get(ATTR_VALUE2)
value3 = call.data.get(ATTR_VALUE3) value3 = call.data.get(ATTR_VALUE3)
target_keys = dict() target_keys = {}
for target in targets: for target in targets:
if target not in api_keys: if target not in api_keys:
_LOGGER.error("No IFTTT api key for %s", target) _LOGGER.error("No IFTTT api key for %s", target)

View File

@ -171,7 +171,7 @@ def _check_deprecated_turn_off(hass, turn_off_action):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Kodi platform.""" """Set up the Kodi platform."""
if DOMAIN not in hass.data: if DOMAIN not in hass.data:
hass.data[DOMAIN] = dict() hass.data[DOMAIN] = {}
unique_id = None unique_id = None
# Is this a manual configuration? # Is this a manual configuration?

View File

@ -119,7 +119,7 @@ class MeteoFranceWeather(WeatherEntity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes.""" """Return the state attributes."""
data = dict() data = {}
if self._data and "next_rain" in self._data: if self._data and "next_rain" in self._data:
data["next_rain"] = self._data["next_rain"] data["next_rain"] = self._data["next_rain"]
return data return data

View File

@ -124,7 +124,7 @@ class MHZClient:
"""Initialize the sensor.""" """Initialize the sensor."""
self.co2sensor = co2sens self.co2sensor = co2sens
self._serial = serial self._serial = serial
self.data = dict() self.data = {}
@Throttle(MIN_TIME_BETWEEN_UPDATES) @Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self): def update(self):

View File

@ -68,7 +68,7 @@ class MpcHcDevice(MediaPlayerDevice):
"""Initialize the MPC-HC device.""" """Initialize the MPC-HC device."""
self._name = name self._name = name
self._url = url self._url = url
self._player_variables = dict() self._player_variables = {}
self._available = False self._available = False
def update(self): def update(self):
@ -83,7 +83,7 @@ class MpcHcDevice(MediaPlayerDevice):
self._available = True self._available = True
except requests.exceptions.RequestException: except requests.exceptions.RequestException:
_LOGGER.error("Could not connect to MPC-HC at: %s", self._url) _LOGGER.error("Could not connect to MPC-HC at: %s", self._url)
self._player_variables = dict() self._player_variables = {}
self._available = False self._available = False
def _send_command(self, command_id): def _send_command(self, command_id):

View File

@ -57,7 +57,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Nanoleaf light.""" """Set up the Nanoleaf light."""
if DATA_NANOLEAF not in hass.data: if DATA_NANOLEAF not in hass.data:
hass.data[DATA_NANOLEAF] = dict() hass.data[DATA_NANOLEAF] = {}
token = "" token = ""
if discovery_info is not None: if discovery_info is not None:

View File

@ -161,9 +161,9 @@ class Plant(Entity):
def __init__(self, name, config): def __init__(self, name, config):
"""Initialize the Plant component.""" """Initialize the Plant component."""
self._config = config self._config = config
self._sensormap = dict() self._sensormap = {}
self._readingmap = dict() self._readingmap = {}
self._unit_of_measurement = dict() self._unit_of_measurement = {}
for reading, entity_id in config["sensors"].items(): for reading, entity_id in config["sensors"].items():
self._sensormap[entity_id] = reading self._sensormap[entity_id] = reading
self._readingmap[reading] = entity_id self._readingmap[reading] = entity_id
@ -371,7 +371,7 @@ class DailyHistory:
"""Create new DailyHistory with a maximum length of the history.""" """Create new DailyHistory with a maximum length of the history."""
self.max_length = max_length self.max_length = max_length
self._days = None self._days = None
self._max_dict = dict() self._max_dict = {}
self.max = None self.max = None
def add_measurement(self, value, timestamp=None): def add_measurement(self, value, timestamp=None):

View File

@ -157,7 +157,7 @@ class RememberTheMilkConfiguration:
"""Create new instance of configuration.""" """Create new instance of configuration."""
self._config_file_path = hass.config.path(CONFIG_FILE_NAME) self._config_file_path = hass.config.path(CONFIG_FILE_NAME)
if not os.path.isfile(self._config_file_path): if not os.path.isfile(self._config_file_path):
self._config = dict() self._config = {}
return return
try: try:
_LOGGER.debug("Loading configuration from file: %s", self._config_file_path) _LOGGER.debug("Loading configuration from file: %s", self._config_file_path)
@ -168,7 +168,7 @@ class RememberTheMilkConfiguration:
"Failed to load configuration file, creating a new one: %s", "Failed to load configuration file, creating a new one: %s",
self._config_file_path, self._config_file_path,
) )
self._config = dict() self._config = {}
def save_config(self): def save_config(self):
"""Write the configuration to a file.""" """Write the configuration to a file."""
@ -198,9 +198,9 @@ class RememberTheMilkConfiguration:
def _initialize_profile(self, profile_name): def _initialize_profile(self, profile_name):
"""Initialize the data structures for a profile.""" """Initialize the data structures for a profile."""
if profile_name not in self._config: if profile_name not in self._config:
self._config[profile_name] = dict() self._config[profile_name] = {}
if CONF_ID_MAP not in self._config[profile_name]: if CONF_ID_MAP not in self._config[profile_name]:
self._config[profile_name][CONF_ID_MAP] = dict() self._config[profile_name][CONF_ID_MAP] = {}
def get_rtm_id(self, profile_name, hass_id): def get_rtm_id(self, profile_name, hass_id):
"""Get the RTM ids for a Home Assistant task ID. """Get the RTM ids for a Home Assistant task ID.

View File

@ -184,7 +184,7 @@ class SpeechToTextView(HomeAssistantView):
return None return None
# Convert Header data # Convert Header data
args = dict() args = {}
for value in data: for value in data:
value = value.strip() value = value.strip()
args[value.partition("=")[0]] = value.partition("=")[2] args[value.partition("=")[0]] = value.partition("=")[2]

View File

@ -90,7 +90,7 @@ class Ted5000Gateway:
def __init__(self, url): def __init__(self, url):
"""Initialize the data object.""" """Initialize the data object."""
self.url = url self.url = url
self.data = dict() self.data = {}
@Throttle(MIN_TIME_BETWEEN_UPDATES) @Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self): def update(self):

View File

@ -11,7 +11,7 @@ _LOGGER = logging.getLogger(__name__)
def initialise_templates(hass, templates, attribute_templates=None): def initialise_templates(hass, templates, attribute_templates=None):
"""Initialise templates and attribute templates.""" """Initialise templates and attribute templates."""
if attribute_templates is None: if attribute_templates is None:
attribute_templates = dict() attribute_templates = {}
for template in chain(templates.values(), attribute_templates.values()): for template in chain(templates.values(), attribute_templates.values()):
if template is None: if template is None:
continue continue
@ -23,7 +23,7 @@ def extract_entities(
): ):
"""Extract entity ids from templates and attribute templates.""" """Extract entity ids from templates and attribute templates."""
if attribute_templates is None: if attribute_templates is None:
attribute_templates = dict() attribute_templates = {}
entity_ids = set() entity_ids = set()
if manual_entity_ids is None: if manual_entity_ids is None:
invalid_templates = [] invalid_templates = []

View File

@ -94,7 +94,7 @@ class UbusDeviceScanner(DeviceScanner):
def _generate_mac2name(self): def _generate_mac2name(self):
"""Return empty MAC to name dict. Overridden if DHCP server is set.""" """Return empty MAC to name dict. Overridden if DHCP server is set."""
self.mac2name = dict() self.mac2name = {}
@_refresh_on_access_denied @_refresh_on_access_denied
def get_device_name(self, device): def get_device_name(self, device):
@ -170,7 +170,7 @@ class DnsmasqUbusDeviceScanner(UbusDeviceScanner):
self.url, self.session_id, "call", "file", "read", path=self.leasefile self.url, self.session_id, "call", "file", "read", path=self.leasefile
) )
if result: if result:
self.mac2name = dict() self.mac2name = {}
for line in result["data"].splitlines(): for line in result["data"].splitlines():
hosts = line.split(" ") hosts = line.split(" ")
self.mac2name[hosts[1].upper()] = hosts[3] self.mac2name[hosts[1].upper()] = hosts[3]
@ -185,7 +185,7 @@ class OdhcpdUbusDeviceScanner(UbusDeviceScanner):
def _generate_mac2name(self): def _generate_mac2name(self):
result = _req_json_rpc(self.url, self.session_id, "call", "dhcp", "ipv4leases") result = _req_json_rpc(self.url, self.session_id, "call", "dhcp", "ipv4leases")
if result: if result:
self.mac2name = dict() self.mac2name = {}
for device in result["device"].values(): for device in result["device"].values():
for lease in device["leases"]: for lease in device["leases"]:
mac = lease["mac"] # mac = aabbccddeeff mac = lease["mac"] # mac = aabbccddeeff

View File

@ -79,7 +79,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Volumio platform.""" """Set up the Volumio platform."""
if DATA_VOLUMIO not in hass.data: if DATA_VOLUMIO not in hass.data:
hass.data[DATA_VOLUMIO] = dict() hass.data[DATA_VOLUMIO] = {}
# This is a manual configuration? # This is a manual configuration?
if discovery_info is None: if discovery_info is None:

View File

@ -106,7 +106,7 @@ class TestGoogleWifiSensor(unittest.TestCase):
conditions = google_wifi.MONITORED_CONDITIONS.keys() conditions = google_wifi.MONITORED_CONDITIONS.keys()
self.api = google_wifi.GoogleWifiAPI("localhost", conditions) self.api = google_wifi.GoogleWifiAPI("localhost", conditions)
self.name = NAME self.name = NAME
self.sensor_dict = dict() self.sensor_dict = {}
for condition, cond_list in google_wifi.MONITORED_CONDITIONS.items(): for condition, cond_list in google_wifi.MONITORED_CONDITIONS.items():
sensor = google_wifi.GoogleWifiSensor(self.api, self.name, condition) sensor = google_wifi.GoogleWifiSensor(self.api, self.name, condition)
name = f"{self.name}_{condition}" name = f"{self.name}_{condition}"

View File

@ -144,7 +144,7 @@ async def test_template_position(hass, calls):
await hass.async_block_till_done() await hass.async_block_till_done()
entity = hass.states.get("cover.test") entity = hass.states.get("cover.test")
attrs = dict() attrs = {}
attrs["position"] = 42 attrs["position"] = 42
hass.states.async_set(entity.entity_id, entity.state, attributes=attrs) hass.states.async_set(entity.entity_id, entity.state, attributes=attrs)
await hass.async_block_till_done() await hass.async_block_till_done()