Skip to content

Commit

Permalink
Merge pull request #358 from WillCodeForCats/code-quality
Browse files Browse the repository at this point in the history
Complete typing for switch platform
  • Loading branch information
WillCodeForCats authored Jul 8, 2023
2 parents 7fc2a87 + e399542 commit 194cdce
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions custom_components/solaredge_modbus_multi/switch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Switch platform for SolarEdge Modbus Multi."""
from __future__ import annotations

import logging
from typing import Any

from homeassistant.components.switch import SwitchEntity
from homeassistant.config_entries import ConfigEntry
Expand Down Expand Up @@ -47,7 +49,7 @@ class SolarEdgeSwitchBase(CoordinatorEntity, SwitchEntity):
should_poll = False
_attr_has_entity_name = True

def __init__(self, platform, config_entry, coordinator):
def __init__(self, platform, config_entry, coordinator) -> None:
"""Pass coordinator to CoordinatorEntity."""
super().__init__(coordinator)
"""Initialize the sensor."""
Expand Down Expand Up @@ -78,7 +80,7 @@ def _handle_coordinator_update(self) -> None:
class SolarEdgeExternalProduction(SolarEdgeSwitchBase):
entity_category = EntityCategory.CONFIG

def __init__(self, platform, config_entry, coordinator):
def __init__(self, platform, config_entry, coordinator) -> None:
super().__init__(platform, config_entry, coordinator)
"""Initialize the sensor."""

Expand Down Expand Up @@ -112,7 +114,7 @@ def is_on(self) -> bool | None:
except KeyError:
return None

async def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the entity on."""
set_bits = int(self._platform.decoded_model["E_Lim_Ctl_Mode"])
set_bits = set_bits | (1 << 10)
Expand All @@ -121,7 +123,7 @@ async def async_turn_on(self, **kwargs):
await self._platform.write_registers(address=57344, payload=set_bits)
await self.async_update()

async def async_turn_off(self, **kwargs):
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the entity off."""
set_bits = int(self._platform.decoded_model["E_Lim_Ctl_Mode"])
set_bits = set_bits & ~(1 << 10)
Expand All @@ -134,7 +136,7 @@ async def async_turn_off(self, **kwargs):
class SolarEdgeNegativeSiteLimit(SolarEdgeSwitchBase):
entity_category = EntityCategory.CONFIG

def __init__(self, platform, config_entry, coordinator):
def __init__(self, platform, config_entry, coordinator) -> None:
super().__init__(platform, config_entry, coordinator)
"""Initialize the sensor."""

Expand Down Expand Up @@ -164,7 +166,7 @@ def is_on(self) -> bool | None:
except KeyError:
return None

async def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the entity on."""
set_bits = int(self._platform.decoded_model["E_Lim_Ctl_Mode"])
set_bits = set_bits | (1 << 11)
Expand All @@ -173,7 +175,7 @@ async def async_turn_on(self, **kwargs):
await self._platform.write_registers(address=57344, payload=set_bits)
await self.async_update()

async def async_turn_off(self, **kwargs):
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the entity off."""
set_bits = int(self._platform.decoded_model["E_Lim_Ctl_Mode"])
set_bits = set_bits & ~(1 << 11)
Expand All @@ -186,7 +188,7 @@ async def async_turn_off(self, **kwargs):
class SolarEdgeGridControl(SolarEdgeSwitchBase):
entity_category = EntityCategory.CONFIG

def __init__(self, platform, config_entry, coordinator):
def __init__(self, platform, config_entry, coordinator) -> None:
super().__init__(platform, config_entry, coordinator)
"""Initialize the sensor."""

Expand All @@ -210,7 +212,7 @@ def is_on(self) -> bool | None:
except KeyError:
return None

async def async_turn_on(self, **kwargs):
async def async_turn_on(self, **kwargs: Any) -> None:
_LOGGER.debug(f"set {self.unique_id} to 0x1")
builder = BinaryPayloadBuilder(byteorder=Endian.Big, wordorder=Endian.Little)
builder.add_32bit_int(0x1)
Expand All @@ -219,7 +221,7 @@ async def async_turn_on(self, **kwargs):
)
await self.async_update()

async def async_turn_off(self, **kwargs):
async def async_turn_off(self, **kwargs: Any) -> None:
_LOGGER.debug(f"set {self.unique_id} to 0x0")
builder = BinaryPayloadBuilder(byteorder=Endian.Big, wordorder=Endian.Little)
builder.add_32bit_int(0x0)
Expand Down

0 comments on commit 194cdce

Please sign in to comment.