Rename descriptor to feature

This commit is contained in:
Teemu Rytilahti
2024-02-14 18:59:11 +01:00
parent 288b5cacce
commit 5dc190837c
9 changed files with 100 additions and 106 deletions

View File

@@ -4,7 +4,7 @@ try:
except ImportError:
from pydantic import BaseModel
from ...descriptors import Descriptor, DescriptorType
from ...feature import Feature, FeatureType
from .module import IotModule
@@ -28,13 +28,14 @@ class Cloud(IotModule):
def __init__(self, device, module):
super().__init__(device, module)
self.add_descriptor(
Descriptor(
device=self,
name="Cloud Connection",
self.add_feature(
Feature(
device=device,
container=self,
name="Cloud connection",
icon="mdi:cloud",
attribute_getter="is_connected",
type=DescriptorType.BinarySensor,
type=FeatureType.BinarySensor,
)
)

View File

@@ -4,8 +4,8 @@ import logging
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Dict
from ...descriptors import Descriptor
from ...exceptions import SmartDeviceException
from ...feature import Feature
if TYPE_CHECKING:
from kasa.iot import IotDevice
@@ -35,14 +35,14 @@ class IotModule(ABC):
def __init__(self, device: "IotDevice", module: str):
self._device = device
self._module = module
self._module_descriptors: Dict[str, Descriptor] = {}
self._module_features: Dict[str, Feature] = {}
def add_descriptor(self, desc):
def add_feature(self, feature: Feature):
"""Add module descriptor."""
module_desc_name = f"{self._module}_{desc.name}"
if module_desc_name in self._module_descriptors:
raise Exception("Duplicate name detected %s" % module_desc_name)
self._module_descriptors[module_desc_name] = desc
feature_name = f"{self._module}_{feature.name}"
if feature_name in self._module_features:
raise SmartDeviceException("Duplicate name detected %s" % feature_name)
self._module_features[feature_name] = feature
@abstractmethod
def query(self):