Skip to content

Commit

Permalink
Ruff Format
Browse files Browse the repository at this point in the history
  • Loading branch information
wimb0 committed Feb 11, 2025
1 parent 3cf453c commit 1fb0525
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
2 changes: 2 additions & 0 deletions custom_components/saj_modbus/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The SAJ Modbus Integration."""

import asyncio
import logging

Expand Down Expand Up @@ -60,6 +61,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):

return True


async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Unload SAJ mobus entry."""

Expand Down
4 changes: 2 additions & 2 deletions custom_components/saj_modbus/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import voluptuous as vol
from homeassistant import config_entries

from homeassistant.const import (CONF_HOST, CONF_NAME, CONF_PORT,
CONF_SCAN_INTERVAL)
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT, CONF_SCAN_INTERVAL
from homeassistant.core import HomeAssistant, callback

from .const import DEFAULT_NAME, DEFAULT_PORT, DEFAULT_SCAN_INTERVAL, DOMAIN
Expand Down Expand Up @@ -40,6 +39,7 @@ def saj_modbus_entries(hass: HomeAssistant):
for config_entry in hass.config_entries.async_entries(DOMAIN)
}


class SAJModbusConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""SAJ Modbus configflow."""

Expand Down
2 changes: 2 additions & 0 deletions custom_components/saj_modbus/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
class SajModbusNumberEntityDescription(NumberEntityDescription):
"""A class that describes SAJ number entities."""


NUMBER_TYPES: dict[str, list[SajModbusNumberEntityDescription]] = {
"LimitPower": SajModbusNumberEntityDescription(
name="Limit Power",
Expand All @@ -48,6 +49,7 @@ class SajModbusNumberEntityDescription(NumberEntityDescription):
class SajModbusSensorEntityDescription(SensorEntityDescription):
"""A class that describes SAJ sensor entities."""


COUNTER_SENSOR_TYPES: dict[str, list[SajModbusSensorEntityDescription]] = {
"TodayEnergy": SajModbusSensorEntityDescription(
name="Power generation on current day",
Expand Down
18 changes: 10 additions & 8 deletions custom_components/saj_modbus/hub.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
"""SAJ Modbus Hub."""

from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from voluptuous.validators import Number
import logging
import threading
from datetime import datetime, timedelta
from homeassistant.core import (
CALLBACK_TYPE,
callback,
HomeAssistant
)
from homeassistant.core import CALLBACK_TYPE, callback, HomeAssistant
from homeassistant.helpers import entity_registry
from homeassistant.components.number import DOMAIN as NUMBER_DOMAIN
from pymodbus.client import ModbusTcpClient
Expand Down Expand Up @@ -156,8 +153,11 @@ def read_modbus_realtime_data(self) -> dict:
mpvmode = decoder.decode_16bit_uint()

if mpvmode == 2:
data["limitpower"] = (110 if mpvmode != self.data.get("mpvmode")
else self.data.get("limitpower"))
data["limitpower"] = (
110
if mpvmode != self.data.get("mpvmode")
else self.data.get("limitpower")
)

data["mpvmode"] = mpvmode

Expand Down Expand Up @@ -323,7 +323,9 @@ def set_limitpower(self, value: float) -> None:
"""Limit the power output of the inverter."""
if self.limiter_is_disabled():
return
response = self._write_registers(unit=1, address=0x801F, values=[int(value * 10)])
response = self._write_registers(
unit=1, address=0x801F, values=[int(value * 10)]
)
if response.isError():
return
self.data["limitpower"] = value
Expand Down
2 changes: 1 addition & 1 deletion custom_components/saj_modbus/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Based up on the original of pyModbus https://github.com/pymodbus-dev/pymodbus/blob/v3.8.3/pymodbus/payload.py
"""

from __future__ import annotations


Expand Down Expand Up @@ -274,7 +275,6 @@ def __init__(self, payload, byteorder=Endian.LITTLE, wordorder=Endian.BIG):
self._byteorder = byteorder
self._wordorder = wordorder


@classmethod
def fromRegisters(
cls,
Expand Down
7 changes: 2 additions & 5 deletions custom_components/saj_modbus/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ def unique_id(self) -> str | None:
@property
def native_value(self):
"""Return the native value of the sensor."""
return (
self.coordinator.data.get(self.entity_description.key, None)
)
return self.coordinator.data.get(self.entity_description.key, None)


class SajCounterSensor(SajSensor):
"""Representation of a SAJ Modbus counter sensor."""
Expand All @@ -98,5 +97,3 @@ def native_value(self):
if self.coordinator.data.get("mpvmode") in (1, 2): # "Waiting" or "Normal"
return self.coordinator.data.get(self.entity_description.key)
return None


19 changes: 8 additions & 11 deletions custom_components/saj_modbus/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

from homeassistant.const import ATTR_DEVICE_ID
from homeassistant.core import HomeAssistant, ServiceCall, callback
from homeassistant.helpers import (
device_registry as dr,
config_validation as cv
)
from homeassistant.helpers import device_registry as dr, config_validation as cv

from .const import DOMAIN as SAJ_DOMAIN

Expand All @@ -19,10 +16,12 @@
SERVICE_SET_DATE_TIME = "set_datetime"

SERVICE_SET_DATE_TIME_SCHEMA = vol.All(
vol.Schema({
vol.Required(ATTR_DEVICE_ID): str,
vol.Optional(ATTR_DATETIME): cv.datetime,
})
vol.Schema(
{
vol.Required(ATTR_DEVICE_ID): str,
vol.Optional(ATTR_DATETIME): cv.datetime,
}
)
)

SUPPORTED_SERVICES = (SERVICE_SET_DATE_TIME,)
Expand Down Expand Up @@ -67,7 +66,5 @@ async def async_set_date_time(hass: HomeAssistant, data: Mapping[str, Any]) -> N

hub = hass.data[SAJ_DOMAIN][device_entry.name]["hub"]
await hass.async_add_executor_job(
hub.set_date_and_time,
data.get(ATTR_DATETIME, None)
hub.set_date_and_time, data.get(ATTR_DATETIME, None)
)

0 comments on commit 1fb0525

Please sign in to comment.