Skip to content

Commit

Permalink
fix pysort issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Wheaton authored and Dan Wheaton committed Jan 8, 2024
1 parent c56fb4c commit e34039a
Showing 1 changed file with 7 additions and 55 deletions.
62 changes: 7 additions & 55 deletions custom_components/linktap/valve.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@
import voluptuous as vol
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
from homeassistant.components.valve import ValveEntity, ValveEntityFeature
from homeassistant.const import (
ATTR_ENTITY_ID,
CONF_ENTITY_ID,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_OFF,
STATE_ON,
)
from homeassistant.const import (ATTR_ENTITY_ID, CONF_ENTITY_ID,
SERVICE_TURN_OFF, SERVICE_TURN_ON, STATE_OFF,
STATE_ON)
from homeassistant.core import callback
from homeassistant.helpers import entity_platform, service, entity_registry as er
from homeassistant.helpers import entity_platform, service
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers import service
from homeassistant.helpers.entity import *
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand All @@ -29,8 +26,7 @@

_LOGGER = logging.getLogger(__name__)

from .const import (ATTR_STATE, DOMAIN, GW_IP,
MANUFACTURER, NAME, TAP_ID)
from .const import ATTR_STATE, DOMAIN, GW_IP, MANUFACTURER, NAME, TAP_ID


async def async_setup_entry(
Expand All @@ -56,20 +52,15 @@ def __init__(self, coordinator: DataUpdateCoordinator, hass, tap):
super().__init__(coordinator)
self._state = None
self._name = tap[NAME]
#self._id = tap[TAP_ID]
self.tap_id = tap[TAP_ID]
#self.tap_api = coordinator.tap_api
self.platform = "valve"
self.hass = hass
self._attr_supported_features = ValveEntityFeature.OPEN | ValveEntityFeature.CLOSE
self._attr_reports_position = False
self._attr_unique_id = slugify(f"{DOMAIN}_{self.platform}_{self.tap_id}")
#self._attr_icon = "mdi:water-pump"
self._attrs = {
"data": self.coordinator.data,
"switch": self.switch_entity,
# "duration_entity": self.duration_entity,
# "volume_entity": self.volume_entity
}
self._attr_device_info = DeviceInfo(
identifiers={
Expand All @@ -94,27 +85,7 @@ def switch_entity(self):
name = name.replace("-", "_")
return f"switch.{DOMAIN}_{name}".lower()

# @property
# def duration_entity(self):
# name = self._name.replace(" ", "_")
# name = name.replace("-", "_")
# return f"number.{DOMAIN}_{name}_watering_duration".lower()

# @property
# def volume_entity(self):
# name = self._name.replace(" ", "_")
# name = name.replace("-", "_")
# return f"number.{DOMAIN}_{name}_watering_volume".lower()

async def async_open_valve(self, **kwargs):
#duration = self.get_watering_duration()
#seconds = int(float(duration)) * 60
#volume = self.get_watering_volume()
#watering_volume = None
#if volume != DEFAULT_VOL:
# watering_volume = volume
#gw_id = self.coordinator.get_gw_id()
#attributes = await self.tap_api.turn_on(gw_id, self.tap_id, seconds, self.get_watering_volume())
"""Open the valve."""
await self.hass.services.async_call(
SWITCH_DOMAIN,
Expand All @@ -124,8 +95,6 @@ async def async_open_valve(self, **kwargs):
context=self._context,
)
await self.coordinator.async_request_refresh()
#self.control_result = await self.set_state(go="open")
#self.async_write_ha_state()

async def async_close_valve(self, **kwargs):
"""Close valve."""
Expand All @@ -137,8 +106,6 @@ async def async_close_valve(self, **kwargs):
context=self._context,
)
await self.coordinator.async_request_refresh()
#self.control_result = await self.set_state(go="close")
#self.async_write_ha_state()

@property
def extra_state_attributes(self):
Expand All @@ -161,12 +128,6 @@ def async_state_changed_listener(
@property
def state(self):
status = self.coordinator.data
#self._attrs["data"] = status
#_LOGGER.debug(f"Switch Status: {status}")
#duration = self.get_watering_duration()
#_LOGGER.debug(f"Set duration:{duration}")
#volume = self.get_watering_volume()
#_LOGGER.debug(f"Set volume:{volume}")
self._attrs[ATTR_STATE] = status[ATTR_STATE]
state = "unknown"
if status[ATTR_STATE]:
Expand All @@ -177,22 +138,13 @@ def state(self):
self._attr_is_closed = state != "open"
return state

@property
def is_closed(self):
return self.state() == "closed"

@property
def is_open(self):
return self.state() == "open"

@property
def device_info(self) -> DeviceInfo:
return self._attr_device_info

async def _pause_tap(self, hours=False):
if not hours:
hours = 1
# Currently hard coding 1 hour for testing
_LOGGER.debug(f"Pausing {self.entity_id} for {hours} hours")
await self.tap_api.pause_tap(self._gw_id, self.tap_id, hours)
await self.coordinator.async_request_refresh()

0 comments on commit e34039a

Please sign in to comment.