custom-components / pyscript

Pyscript adds rich Python scripting to HASS
Apache License 2.0
874 stars 46 forks source link

cannot access attributes of climate entity, bool returned instead #522

Closed phsdv closed 1 year ago

phsdv commented 1 year ago

Trying to get the attributes of one of my climate entities but it throws an error The code: attr_inside = state.getattr(climate.smart_kantoor_vloerverwarming) The error: Exception in <file.office_heating.thermostat_office_sethigh> line 45: attr_inside = state.getattr(climate.smart_kantoor_vloerverwarming) ^ AttributeError: 'bool' object has no attribute 'smart_kantoor_vloerverwarming' Which is unexpected as this entity has about 10 different attributes. image A bool is returned instead of a dictionary with the attributes.

ALERTua commented 1 year ago
import pprint

@time_trigger
def tryouts(trigger_type=None, var_name=None, value=None, old_value=None, context=None, **kwargs):
    ent = hass.states.get('climate.ac_office')
    log.debug(ent)
    attrs = ent.attributes
    log.debug(pprint.pformat(attrs))

(or just state.getattr('climate.ac_office')) resulted in

2023-09-06 12:48:48.337 DEBUG (MainThread) [custom_components.pyscript.file.tryouts.tryouts] <state climate.ac_office=fan_only; hvac_modes=[<HVACMode.FAN_ONLY: 'fan_only'>, <HVACMode.DRY: 'dry'>, <HVACMode.COOL: 'cool'>, <HVACMode.HEAT: 'heat'>, <HVACMode.HEAT_COOL: 'heat_cool'>, <HVACMode.OFF: 'off'>], min_temp=7, max_temp=35, target_temp_step=1, fan_modes=['Auto', 'Silence', '1', '2', '3', '4', '5'], preset_modes=['none', 'away', 'eco', 'boost'], swing_modes=['Off', 'Vertical', 'Horizontal', '3D'], current_temperature=25.0, temperature=None, fan_mode=Silence, preset_mode=none, swing_mode=Horizontal, friendly_name=OfficeAC, supported_features=57 @ 2023-09-06T12:43:57.009294+03:00>
2023-09-06 12:48:48.337 DEBUG (MainThread) [custom_components.pyscript.file.tryouts.tryouts] {'current_temperature': 25.0,
 'fan_mode': 'Silence',
 'fan_modes': ['Auto', 'Silence', '1', '2', '3', '4', '5'],
 'friendly_name': 'OfficeAC',
 'hvac_modes': [,
                ,
                ,
                ,
                ,
                ],
 'max_temp': 35,
 'min_temp': 7,
 'preset_mode': 'none',
 'preset_modes': ['none', 'away', 'eco', 'boost'],
 'supported_features': ,
 'swing_mode': 'Horizontal',
 'swing_modes': ['Off', 'Vertical', 'Horizontal', '3D'],
 'target_temp_step': 1,
 'temperature': None}

climate.smart_kantoor_vloerverwarming is an entity State instance 'climate.smart_kantoor_vloerverwarming' is the entity ID state.getattr() accepts only entity IDs

phsdv commented 1 year ago

ohh, I forgot the '' quotes.