Skip to content

Commit

Permalink
Address linting
Browse files Browse the repository at this point in the history
  • Loading branch information
scottyphillips committed Mar 21, 2024
1 parent 04a4a0f commit 380d184
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 22 deletions.
6 changes: 3 additions & 3 deletions custom_components/echonetlite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@
MAX_UPDATE_BATCH_SIZE = 10
MIN_UPDATE_BATCH_SIZE = 3

def get_device_name(
connector, config
) -> str:

def get_device_name(connector, config) -> str:
if connector._name:
return connector._name
if connector._instance._eojci > 1:
return f"{config.title} {connector._instance._eojci}"
return config.title


def get_name_by_epc_code(
jgc: int, jcc: int, code: int, unknown: str | None = None
) -> str:
Expand Down
64 changes: 46 additions & 18 deletions custom_components/echonetlite/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,28 @@
TILT_RANGE = (1, 180)
_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(hass, config_entry, async_add_devices):
"""Set up entry."""
entities = []
for entity in hass.data[DOMAIN][config_entry.entry_id]:
if entity['instance']['eojgc'] == 0x02 and entity['instance']['eojcc'] in (0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66):
if entity["instance"]["eojgc"] == 0x02 and entity["instance"]["eojcc"] in (
0x60,
0x61,
0x62,
0x63,
0x64,
0x65,
0x66,
):
# 0x60: "Electrically operated blind/shade"
# 0x61: "Electrically operated shutter"
# 0x62: "Electrically operated curtain"
# 0x63: "Electrically operated rain sliding door/shutter"
# 0x64: "Electrically operated gate"
# 0x65: "Electrically operated window"
# 0x66: "Automatically operated entrance door/sliding door"
entities.append(EchonetCover(entity['echonetlite'], config_entry))
entities.append(EchonetCover(entity["echonetlite"], config_entry))
async_add_devices(entities, True)


Expand All @@ -52,7 +61,9 @@ def __init__(self, connector, config):
self._name = name
self._device_name = name
self._connector = connector # new line
self._uid = self._connector._uidi if self._connector._uidi else self._connector._uid
self._uid = (
self._connector._uidi if self._connector._uidi else self._connector._uid
)
self._attr_is_closed = False
self._server_state = self._connector._api._state[
self._connector._instance._host
Expand All @@ -71,7 +82,7 @@ def __init__(self, connector, config):
CoverEntityFeature.OPEN_TILT
| CoverEntityFeature.CLOSE_TILT
# not supported individually (just global STOP)
#| CoverEntityFeature.STOP_TILT
# | CoverEntityFeature.STOP_TILT
| CoverEntityFeature.SET_TILT_POSITION
)

Expand Down Expand Up @@ -115,7 +126,9 @@ async def async_open_cover_tilt(self, **kwargs: Any) -> None:
self._connector._update_data[ENL_BLIND_ANGLE] = hex(180)

async def async_set_cover_tilt_position(self, **kwargs: Any) -> None:
tilt = math.ceil(percentage_to_ranged_value(TILT_RANGE, kwargs[ATTR_TILT_POSITION]))
tilt = math.ceil(
percentage_to_ranged_value(TILT_RANGE, kwargs[ATTR_TILT_POSITION])
)
await self._connector._instance.setMessage(ENL_BLIND_ANGLE, tilt)
self._connector._update_data[ENL_BLIND_ANGLE] = hex(tilt)

Expand All @@ -131,16 +144,28 @@ async def async_update(self):
await self._connector.async_update()

def update_attr(self):
self._attr_current_cover_position = int(self._connector._update_data[ENL_OPENING_LEVEL], 16)
self._attr_current_cover_position = int(
self._connector._update_data[ENL_OPENING_LEVEL], 16
)
self._attr_is_closed = self._attr_current_cover_position == 0
if ENL_OPENCLOSE_STATUS in self._connector._update_data:
self._attr_is_opening = int(self._connector._update_data[ENL_OPENCLOSE_STATUS], 16) == 0x43
self._attr_is_closing = int(self._connector._update_data[ENL_OPENCLOSE_STATUS], 16) == 0x44
self._attr_is_opening = (
int(self._connector._update_data[ENL_OPENCLOSE_STATUS], 16) == 0x43
)
self._attr_is_closing = (
int(self._connector._update_data[ENL_OPENCLOSE_STATUS], 16) == 0x44
)
else:
self._attr_is_opening = self._connector._update_data[ENL_OPENSTATE] == "open"
self._attr_is_closing = self._connector._update_data[ENL_OPENSTATE] == "close"
self._attr_is_opening = (
self._connector._update_data[ENL_OPENSTATE] == "open"
)
self._attr_is_closing = (
self._connector._update_data[ENL_OPENSTATE] == "close"
)
if ENL_BLIND_ANGLE in self._connector._update_data:
self._attr_current_cover_tilt_position = ranged_value_to_percentage(TILT_RANGE, int(self._connector._update_data[ENL_BLIND_ANGLE], 16))
self._attr_current_cover_tilt_position = ranged_value_to_percentage(
TILT_RANGE, int(self._connector._update_data[ENL_BLIND_ANGLE], 16)
)

@property
def supported_features(self):
Expand All @@ -155,12 +180,15 @@ def unique_id(self):
@property
def device_info(self):
return {
"identifiers": {(
DOMAIN, self._connector._uid,
self._connector._instance._eojgc,
self._connector._instance._eojcc,
self._connector._instance._eojci
)},
"identifiers": {
(
DOMAIN,
self._connector._uid,
self._connector._instance._eojgc,
self._connector._instance._eojcc,
self._connector._instance._eojci,
)
},
"name": self._device_name,
"manufacturer": self._connector._manufacturer
+ (
Expand Down Expand Up @@ -189,7 +217,7 @@ async def async_added_to_hass(self):
self._connector.add_update_option_listener(self.update_option_listener)
self._connector.register_async_update_callbacks(self.async_update_callback)

async def async_update_callback(self, isPush = False):
async def async_update_callback(self, isPush=False):
changed = (
self._olddata != self._connector._update_data
) or self._attr_available != self._server_state["available"]
Expand Down
2 changes: 1 addition & 1 deletion custom_components/echonetlite/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def async_setup_entry(hass, config, async_add_entities, discovery_info=Non
entity["echonetlite"],
config,
op_code,
_enl_op_codes[op_code]
_enl_op_codes[op_code],
)
)

Expand Down

0 comments on commit 380d184

Please sign in to comment.