-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added manual start and stop buttons.
- Loading branch information
1 parent
19aad3f
commit f4a1725
Showing
4 changed files
with
78 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""Button platform for EV Smart Charging.""" | ||
import logging | ||
|
||
from homeassistant.components.button import ButtonEntity | ||
from homeassistant.core import HomeAssistant | ||
|
||
from .const import BUTTON, DOMAIN, ENTITY_NAME_START_BUTTON, ENTITY_NAME_STOP_BUTTON | ||
from .coordinator import EVSmartChargingCoordinator | ||
from .entity import EVSmartChargingEntity | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def async_setup_entry(hass: HomeAssistant, entry, async_add_devices): | ||
"""Setup button platform.""" | ||
_LOGGER.debug("EVSmartCharging.button.py") | ||
coordinator = hass.data[DOMAIN][entry.entry_id] | ||
buttons = [] | ||
buttons.append(EVSmartChargingButtonStart(entry, coordinator)) | ||
buttons.append(EVSmartChargingButtonStop(entry, coordinator)) | ||
async_add_devices(buttons) | ||
|
||
|
||
class EVSmartChargingButton(EVSmartChargingEntity, ButtonEntity): | ||
"""EV Smart Charging button class.""" | ||
|
||
def __init__(self, entry, coordinator: EVSmartChargingCoordinator): | ||
_LOGGER.debug("EVSmartChargingButton.__init__()") | ||
super().__init__(entry) | ||
self.coordinator = coordinator | ||
id_name = self._attr_name.replace(" ", "").lower() | ||
self._attr_unique_id = ".".join([entry.entry_id, BUTTON, id_name]) | ||
_LOGGER.debug("self._attr_unique_id = %s", self._attr_unique_id) | ||
|
||
|
||
class EVSmartChargingButtonStart(EVSmartChargingButton): | ||
"""EV Smart Charging start button class.""" | ||
|
||
_attr_name = ENTITY_NAME_START_BUTTON | ||
|
||
def press(self) -> None: | ||
"""Press the button.""" | ||
_LOGGER.debug("EVSmartChargingButtonStart.press()") | ||
self.coordinator.turn_on_charging() | ||
|
||
|
||
class EVSmartChargingButtonStop(EVSmartChargingButton): | ||
"""EV Smart Charging start button class.""" | ||
|
||
_attr_name = ENTITY_NAME_STOP_BUTTON | ||
|
||
def press(self) -> None: | ||
"""Press the button.""" | ||
_LOGGER.debug("EVSmartChargingButtonStop.press()") | ||
self.coordinator.turn_off_charging() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters