Skip to content

Commit

Permalink
refactor: stick to double quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
andersevenrud committed Dec 31, 2022
1 parent 04e760f commit 849c6a2
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 100 deletions.
140 changes: 70 additions & 70 deletions custom_components/nexa_bridge_x/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,91 +45,91 @@
]

SENSOR_MAP = {
'switchLevel': {
'name': 'Level',
'unit': PERCENTAGE,
'device': None,
'class': SensorStateClass.MEASUREMENT
"switchLevel": {
"name": "Level",
"unit": PERCENTAGE,
"device": None,
"class": SensorStateClass.MEASUREMENT
},
'meter': {
'name': 'Energy',
'unit': ENERGY_KILO_WATT_HOUR,
'device': SensorDeviceClass.ENERGY,
'class': SensorStateClass.TOTAL_INCREASING
"meter": {
"name": "Energy",
"unit": ENERGY_KILO_WATT_HOUR,
"device": SensorDeviceClass.ENERGY,
"class": SensorStateClass.TOTAL_INCREASING
},
'power': {
'name': 'Wattage',
'unit': POWER_WATT,
'device': SensorDeviceClass.POWER,
'class': SensorStateClass.MEASUREMENT
"power": {
"name": "Wattage",
"unit": POWER_WATT,
"device": SensorDeviceClass.POWER,
"class": SensorStateClass.MEASUREMENT
},
'electric_voltage': {
'name': 'Voltage',
'unit': ELECTRIC_POTENTIAL_VOLT,
'device': SensorDeviceClass.VOLTAGE,
'class': SensorStateClass.MEASUREMENT
"electric_voltage": {
"name": "Voltage",
"unit": ELECTRIC_POTENTIAL_VOLT,
"device": SensorDeviceClass.VOLTAGE,
"class": SensorStateClass.MEASUREMENT
},
'electric_ampere': {
'name': 'Amperage',
'unit': ELECTRIC_CURRENT_AMPERE,
'device': SensorDeviceClass.CURRENT,
'class': SensorStateClass.MEASUREMENT
"electric_ampere": {
"name": "Amperage",
"unit": ELECTRIC_CURRENT_AMPERE,
"device": SensorDeviceClass.CURRENT,
"class": SensorStateClass.MEASUREMENT
},
'temperature': {
'name': 'Temperature',
'unit': TEMP_CELSIUS,
'device': SensorDeviceClass.TEMPERATURE,
'class': SensorStateClass.MEASUREMENT
"temperature": {
"name": "Temperature",
"unit": TEMP_CELSIUS,
"device": SensorDeviceClass.TEMPERATURE,
"class": SensorStateClass.MEASUREMENT
},
'humidity': {
'name': 'Temperature',
'unit': PERCENTAGE,
'device': SensorDeviceClass.HUMIDITY,
'class': SensorStateClass.MEASUREMENT
"humidity": {
"name": "Temperature",
"unit": PERCENTAGE,
"device": SensorDeviceClass.HUMIDITY,
"class": SensorStateClass.MEASUREMENT
},
'luminance': {
'name': 'Luminance',
'unit': LIGHT_LUX,
'device': SensorDeviceClass.ILLUMINANCE,
'class': SensorStateClass.MEASUREMENT
"luminance": {
"name": "Luminance",
"unit": LIGHT_LUX,
"device": SensorDeviceClass.ILLUMINANCE,
"class": SensorStateClass.MEASUREMENT
},
}

ENERGY_MAP = {
'total_kilowatt_hours': {
'name': 'NEXA Total kWh',
'unit': ENERGY_KILO_WATT_HOUR,
'device': SensorDeviceClass.ENERGY,
'class': SensorStateClass.TOTAL_INCREASING
"total_kilowatt_hours": {
"name": "NEXA Total kWh",
"unit": ENERGY_KILO_WATT_HOUR,
"device": SensorDeviceClass.ENERGY,
"class": SensorStateClass.TOTAL_INCREASING
},
'current_wattage': {
'name': 'NEXA Current W',
'unit': POWER_WATT,
'device': SensorDeviceClass.POWER,
'class': SensorStateClass.MEASUREMENT
"current_wattage": {
"name": "NEXA Current W",
"unit": POWER_WATT,
"device": SensorDeviceClass.POWER,
"class": SensorStateClass.MEASUREMENT
},
'current_kilowatt_hours': {
'name': 'NEXA Current kWh',
'unit': ENERGY_KILO_WATT_HOUR,
'device': SensorDeviceClass.ENERGY,
'class': SensorStateClass.MEASUREMENT
"current_kilowatt_hours": {
"name": "NEXA Current kWh",
"unit": ENERGY_KILO_WATT_HOUR,
"device": SensorDeviceClass.ENERGY,
"class": SensorStateClass.MEASUREMENT
},
'today_kilowatt_hours': {
'name': 'NEXA Today kWh',
'unit': ENERGY_KILO_WATT_HOUR,
'device': SensorDeviceClass.ENERGY,
'class': SensorStateClass.TOTAL_INCREASING
"today_kilowatt_hours": {
"name": "NEXA Today kWh",
"unit": ENERGY_KILO_WATT_HOUR,
"device": SensorDeviceClass.ENERGY,
"class": SensorStateClass.TOTAL_INCREASING
},
'yesterday_kilowatt_hours': {
'name': 'NEXA Yesterday kWh',
'unit': ENERGY_KILO_WATT_HOUR,
'device': SensorDeviceClass.ENERGY,
'class': SensorStateClass.TOTAL_INCREASING
"yesterday_kilowatt_hours": {
"name": "NEXA Yesterday kWh",
"unit": ENERGY_KILO_WATT_HOUR,
"device": SensorDeviceClass.ENERGY,
"class": SensorStateClass.TOTAL_INCREASING
},
'month_kilowatt_hours': {
'name': 'NEXA Month kWh',
'unit': ENERGY_KILO_WATT_HOUR,
'device': SensorDeviceClass.ENERGY,
'class': SensorStateClass.TOTAL_INCREASING
"month_kilowatt_hours": {
"name": "NEXA Month kWh",
"unit": ENERGY_KILO_WATT_HOUR,
"device": SensorDeviceClass.ENERGY,
"class": SensorStateClass.TOTAL_INCREASING
},
}
20 changes: 10 additions & 10 deletions custom_components/nexa_bridge_x/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(self, coordinator: DataUpdateCoordinator, node: NexaNode):
def _handle_coordinator_update(self) -> None:
node = self.coordinator.get_node_by_id(self.id)
if node:
value = node.get_value('switchLevel')
value = node.get_value("switchLevel")
value_percentage = int(value * 100)

if self.switch_to_state is not None:
Expand Down Expand Up @@ -125,7 +125,7 @@ def __init__(self, coordinator: DataUpdateCoordinator, node: NexaNode):
def _handle_coordinator_update(self) -> None:
node = self.coordinator.get_node_by_id(self.id)
if node:
self._attr_is_on = node.get_value('switchBinary')
self._attr_is_on = node.get_value("switchBinary")
self._attr_name = create_friendly_name("Switch", node)
self.async_write_ha_state()

Expand Down Expand Up @@ -165,16 +165,16 @@ def __init__(
if key in SENSOR_MAP:
friendly = f"{SENSOR_MAP[key]['name']} Sensor"
self._attr_name = create_friendly_name(friendly, node)
self._attr_native_unit_of_measurement = SENSOR_MAP[key]['unit']
self._attr_device_class = SENSOR_MAP[key]['device']
self._attr_state_class = SENSOR_MAP[key]['class']
self._attr_native_unit_of_measurement = SENSOR_MAP[key]["unit"]
self._attr_device_class = SENSOR_MAP[key]["device"]
self._attr_state_class = SENSOR_MAP[key]["class"]

@callback
def _handle_coordinator_update(self) -> None:
node = self.coordinator.get_node_by_id(self.id)
if node:
value = node.get_value(self.key)
if self.key == 'switchLevel':
if self.key == "switchLevel":
self._attr_native_value = int(value * 100)
else:
self._attr_native_value = value
Expand Down Expand Up @@ -220,10 +220,10 @@ def __init__(self, coordinator: DataUpdateCoordinator, attr: str):
self.id = attr
self._attr_native_value = None
self._attr_unique_id = f"nexa_energy_{attr}"
self._attr_name = ENERGY_MAP[attr]['name']
self._attr_native_unit_of_measurement = ENERGY_MAP[attr]['unit']
self._attr_device_class = ENERGY_MAP[attr]['device']
self._attr_state_class = ENERGY_MAP[attr]['class']
self._attr_name = ENERGY_MAP[attr]["name"]
self._attr_native_unit_of_measurement = ENERGY_MAP[attr]["unit"]
self._attr_device_class = ENERGY_MAP[attr]["device"]
self._attr_state_class = ENERGY_MAP[attr]["class"]

@callback
def _handle_coordinator_update(self) -> None:
Expand Down
28 changes: 14 additions & 14 deletions custom_components/nexa_bridge_x/nexa.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class NexaPlatform:
"""Nexa Platform"""

def __init__(self, hass: HomeAssistant, entry: ConfigEntry):
host = entry.data['host']
username = entry.data['username']
password = entry.data['username']
host = entry.data["host"]
username = entry.data["username"]
password = entry.data["username"]

self.api = NexaApi(host, username, password)
self.coordinator = NexaCoordinator(hass, self.api)
Expand Down Expand Up @@ -111,14 +111,14 @@ async def request(
body: Any = None
) -> Response:
"""Performs a request"""
url = "http://%s/v1/%s" % (self.host, endpoint or '')
url = "http://%s/v1/%s" % (self.host, endpoint or "")
auth = aiohttp.BasicAuth(self.username, self.password)

async with aiohttp.ClientSession() as session:
if method == 'post':
if method == "post":
headers = {
'accept': 'application/json',
'content-type': 'application/json'
"accept": "application/json",
"content-type": "application/json"
}

_LOGGER.debug("POST %s: %s", url, json.dumps(body))
Expand All @@ -143,23 +143,23 @@ async def test_connection(self) -> None:

async def fetch_info(self) -> NexaInfoData:
"""Get information about bridge"""
return await self.request('get', 'info')
return await self.request("get", "info")

async def fetch_nodes(self) -> list[NexaNodeData]:
"""Get all configured nodes"""
return await self.request('get', 'nodes')
return await self.request("get", "nodes")

async def fetch_node(self, node: str) -> NexaNodeData:
"""Get a confiured node"""
return await self.request('get', f"nodes/{node}")
return await self.request("get", f"nodes/{node}")

async def fetch_energy(self) -> NexaEnergyData:
"""Get energy stats"""
return await self.request('get', "energy")
return await self.request("get", "energy")

async def fetch_energy_nodes(self) -> NexaEnergyNodeData:
"""Get energy node stats"""
return await self.request('get', "energy/nodes")
return await self.request("get", "energy/nodes")

async def node_call(
self,
Expand All @@ -168,8 +168,8 @@ async def node_call(
value: any
) -> NexaCallData:
"""Perform an action on a device"""
body = {'capability': capability, 'value': value}
return await self.request('post', f"nodes/{node}/call", body)
body = {"capability": capability, "value": value}
return await self.request("post", f"nodes/{node}/call", body)


class NexaInfo:
Expand Down
12 changes: 6 additions & 6 deletions custom_components/nexa_bridge_x/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ async def async_setup_entry(
coordinator = hass.data[DOMAIN][entry.entry_id].coordinator

entities = [
NexaEnergyEntity(coordinator, 'total_kilowatt_hours'),
NexaEnergyEntity(coordinator, 'current_wattage'),
NexaEnergyEntity(coordinator, 'today_kilowatt_hours'),
NexaEnergyEntity(coordinator, 'current_kilowatt_hours'),
NexaEnergyEntity(coordinator, 'yesterday_kilowatt_hours'),
NexaEnergyEntity(coordinator, 'month_kilowatt_hours'),
NexaEnergyEntity(coordinator, "total_kilowatt_hours"),
NexaEnergyEntity(coordinator, "current_wattage"),
NexaEnergyEntity(coordinator, "today_kilowatt_hours"),
NexaEnergyEntity(coordinator, "current_kilowatt_hours"),
NexaEnergyEntity(coordinator, "yesterday_kilowatt_hours"),
NexaEnergyEntity(coordinator, "month_kilowatt_hours"),
]

for node in coordinator.data.nodes:
Expand Down

0 comments on commit 849c6a2

Please sign in to comment.