Skip to content

Commit

Permalink
xx
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewturner committed Jan 9, 2025
1 parent 1ccd718 commit 3aef417
Show file tree
Hide file tree
Showing 22 changed files with 1,034 additions and 1,034 deletions.
14 changes: 7 additions & 7 deletions salusfy/__init__.py → custom_components/salusfy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""The Salus component."""

from .state import State
from .web_client import WebClient
from .thermostat_entity import ThermostatEntity
from .ha_temperature_client import HaTemperatureClient
from .client import Client
"""The Salus component."""

from .state import State
from .web_client import WebClient
from .thermostat_entity import ThermostatEntity
from .ha_temperature_client import HaTemperatureClient
from .client import Client
166 changes: 83 additions & 83 deletions salusfy/client.py → custom_components/salusfy/client.py
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
"""
Client which wraps the web client but handles
the retrieval of current temperature by calling
a specialized client.
"""
import logging

from homeassistant.components.climate.const import (
HVACMode,
HVACAction,
)

from . import (
WebClient,
HaTemperatureClient,
State,
)

_LOGGER = logging.getLogger(__name__)


class Client:
"""Mocks requests to Salus web application"""

def __init__(
self,
web_client: WebClient,
temperature_client: HaTemperatureClient):
"""Initialize the client."""
self._state = None
self._web_client = web_client
self._temperature_client = temperature_client

async def set_temperature(self, temperature: float) -> None:
"""Set new target temperature."""

_LOGGER.info("Delegating set_temperature to web client...")

await self._web_client.set_temperature(temperature)

self._state.target_temperature = temperature

self.assume_hvac_action()

async def set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set HVAC mode, via URL commands."""

_LOGGER.info("Delegating set_hvac_mode to web client...")

await self._web_client.set_hvac_mode(hvac_mode)

self._state.mode = hvac_mode

self.assume_hvac_action()

def assume_hvac_action(self) -> None:
"""Assumes what the hvac action is based on
the mode and current/target temperatures"""
if self._state.mode == HVACMode.OFF:
_LOGGER.info("Assuming action is IDLE...")
self._state.action = HVACAction.IDLE
return

if self._state.target_temperature > self._state.current_temperature:
_LOGGER.info(
"Assuming action is HEATING based on target temperature...")
self._state.action = HVACAction.HEATING
return

_LOGGER.info("Assuming action is IDLE based on target temperature...")
self._state.action = HVACAction.IDLE

async def get_state(self) -> State:
"""Retrieves the status"""

if self._state is None:
_LOGGER.info("Delegating get_state to web client...")
self._state = await self._web_client.get_state()

_LOGGER.info("Updating current temperature from temperature client...")
self._state.current_temperature = await self._temperature_client.current_temperature()

return self._state
"""
Client which wraps the web client but handles
the retrieval of current temperature by calling
a specialized client.
"""
import logging

from homeassistant.components.climate.const import (
HVACMode,
HVACAction,
)

from . import (
WebClient,
HaTemperatureClient,
State,
)

_LOGGER = logging.getLogger(__name__)


class Client:
"""Mocks requests to Salus web application"""

def __init__(
self,
web_client: WebClient,
temperature_client: HaTemperatureClient):
"""Initialize the client."""
self._state = None
self._web_client = web_client
self._temperature_client = temperature_client

async def set_temperature(self, temperature: float) -> None:
"""Set new target temperature."""

_LOGGER.info("Delegating set_temperature to web client...")

await self._web_client.set_temperature(temperature)

self._state.target_temperature = temperature

self.assume_hvac_action()

async def set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set HVAC mode, via URL commands."""

_LOGGER.info("Delegating set_hvac_mode to web client...")

await self._web_client.set_hvac_mode(hvac_mode)

self._state.mode = hvac_mode

self.assume_hvac_action()

def assume_hvac_action(self) -> None:
"""Assumes what the hvac action is based on
the mode and current/target temperatures"""
if self._state.mode == HVACMode.OFF:
_LOGGER.info("Assuming action is IDLE...")
self._state.action = HVACAction.IDLE
return

if self._state.target_temperature > self._state.current_temperature:
_LOGGER.info(
"Assuming action is HEATING based on target temperature...")
self._state.action = HVACAction.HEATING
return

_LOGGER.info("Assuming action is IDLE based on target temperature...")
self._state.action = HVACAction.IDLE

async def get_state(self) -> State:
"""Retrieves the status"""

if self._state is None:
_LOGGER.info("Delegating get_state to web client...")
self._state = await self._web_client.get_state()

_LOGGER.info("Updating current temperature from temperature client...")
self._state.current_temperature = await self._temperature_client.current_temperature()

return self._state
Loading

0 comments on commit 3aef417

Please sign in to comment.