Skip to content

Commit

Permalink
Code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-r committed Dec 27, 2023
1 parent a5bd807 commit c6b25f6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
6 changes: 4 additions & 2 deletions custom_components/ohme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ async def async_setup_entry(hass, entry):
return False

await async_setup_dependencies(hass, config)

hass.data[DOMAIN][DATA_COORDINATOR] = OhmeUpdateCoordinator(hass=hass)
await hass.data[DOMAIN][DATA_COORDINATOR].async_config_entry_first_refresh()

hass.data[DOMAIN][DATA_STATISTICS_COORDINATOR] = OhmeStatisticsUpdateCoordinator(hass=hass)
hass.data[DOMAIN][DATA_STATISTICS_COORDINATOR] = OhmeStatisticsUpdateCoordinator(
hass=hass)
await hass.data[DOMAIN][DATA_STATISTICS_COORDINATOR].async_config_entry_first_refresh()

# Create tasks for each entity type
Expand All @@ -50,6 +51,7 @@ async def async_setup_entry(hass, entry):

return True


async def async_unload_entry(hass, entry):
"""Unload a config entry."""

Expand Down
12 changes: 6 additions & 6 deletions custom_components/ohme/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ async def async_resume_charge(self):
"""Resume a paused charge"""
result = await self._post_request(f"https://api.ohme.io/v1/chargeSessions/{self._serial}/resume", skip_json=True)
return bool(result)

async def async_max_charge(self):
"""Enable max charge"""
result = await self._put_request(f"https://api.ohme.io/v1/chargeSessions/{self._serial}/rule?maxCharge=true")
return bool(result)

async def async_stop_max_charge(self):
"""Stop max charge.
This is more complicated than starting one as we need to give more parameters."""
Expand All @@ -116,7 +116,7 @@ async def async_get_charge_sessions(self, is_retry=False):
"""Try to fetch charge sessions endpoint.
If we get a non 200 response, refresh auth token and try again"""
resp = await self._get_request('https://api.ohme.io/v1/chargeSessions')

if not resp:
return False

Expand All @@ -139,7 +139,7 @@ async def async_update_device_info(self, is_retry=False):
sw_version=device['firmwareVersionLabel'],
serial_number=device['id']
)

self._user_id = resp['user']['id']
self._serial = device['id']
self._device_info = info
Expand All @@ -150,7 +150,8 @@ def _last_second_of_month_timestamp(self):
"""Get the last second of this month."""
dt = datetime.today()
dt = dt.replace(day=1) + timedelta(days=32)
dt = dt.replace(day=1, hour=0, minute=0, second=0, microsecond=0) - timedelta(seconds=1)
dt = dt.replace(day=1, hour=0, minute=0, second=0,
microsecond=0) - timedelta(seconds=1)
return int(dt.timestamp()*1e3)

async def async_get_charge_statistics(self):
Expand All @@ -168,4 +169,3 @@ def get_device_info(self):

def get_unique_id(self, name):
return f"ohme_{self._serial}_{name}"

9 changes: 6 additions & 3 deletions custom_components/ohme/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ async def async_setup_entry(
coordinator = hass.data[DOMAIN][DATA_COORDINATOR]
stats_coordinator = hass.data[DOMAIN][DATA_STATISTICS_COORDINATOR]

sensors = [PowerDrawSensor(coordinator, hass, client), EnergyUsageSensor(stats_coordinator, hass, client)]
sensors = [PowerDrawSensor(coordinator, hass, client), EnergyUsageSensor(
stats_coordinator, hass, client)]

async_add_entities(sensors, update_before_add=True)

Expand All @@ -49,7 +50,8 @@ def __init__(
self.entity_id = generate_entity_id(
"sensor.{}", "ohme_power_draw", hass=hass)

self._attr_device_info = hass.data[DOMAIN][DATA_CLIENT].get_device_info()
self._attr_device_info = hass.data[DOMAIN][DATA_CLIENT].get_device_info(
)

@property
def unique_id(self) -> str:
Expand Down Expand Up @@ -90,7 +92,8 @@ def __init__(
self.entity_id = generate_entity_id(
"sensor.{}", "ohme_accumulative_energy", hass=hass)

self._attr_device_info = hass.data[DOMAIN][DATA_CLIENT].get_device_info()
self._attr_device_info = hass.data[DOMAIN][DATA_CLIENT].get_device_info(
)

@property
def unique_id(self) -> str:
Expand Down
6 changes: 4 additions & 2 deletions custom_components/ohme/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ async def async_turn_on(self):
async def async_turn_off(self):
"""Turn off the switch."""
await self._client.async_resume_charge()

await asyncio.sleep(1)
await self.coordinator.async_refresh()


class OhmeMaxCharge(CoordinatorEntity[OhmeUpdateCoordinator], SwitchEntity):
"""Switch for pausing a charge."""
_attr_name = "Ohme Max Charge"
Expand Down Expand Up @@ -122,7 +123,8 @@ def _handle_coordinator_update(self) -> None:
if self.coordinator.data is None:
self._attr_is_on = False
else:
self._attr_is_on = bool(self.coordinator.data["mode"] == "MAX_CHARGE")
self._attr_is_on = bool(
self.coordinator.data["mode"] == "MAX_CHARGE")

self._last_updated = utcnow()

Expand Down

0 comments on commit c6b25f6

Please sign in to comment.