Skip to content

Commit

Permalink
Add cainfo calls to allow adding mutability of a channel.
Browse files Browse the repository at this point in the history
  • Loading branch information
willrogers committed Oct 15, 2020
1 parent f3db5e8 commit c404981
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions coniql/caplugin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
from typing import AsyncIterator, List, Optional

from aioca import FORMAT_CTRL, FORMAT_TIME, caget, camonitor, caput
from aioca import FORMAT_CTRL, FORMAT_TIME, caget, cainfo, camonitor, caput
from aioca.types import AugmentedValue

from coniql.coniql_schema import Widget
Expand All @@ -25,10 +25,12 @@ def __init__(
value: AugmentedValue,
config: ChannelConfig,
meta_value: AugmentedValue,
writeable: bool = True,
last_channel: "CAChannel" = None,
):
self.value = value
self.meta_value = meta_value
self.writeable = writeable
self.config = config
self.last_channel = last_channel
self.formatter: Optional[ChannelFormatter] = None
Expand All @@ -48,7 +50,7 @@ def get_status(self) -> Optional[ChannelStatus]:
status = ChannelStatus(
quality=CHANNEL_QUALITY_MAP[self.value.severity],
message="",
mutable=True,
mutable=self.writeable,
)
return status

Expand Down Expand Up @@ -115,12 +117,13 @@ class CAPlugin(Plugin):
async def get_channel(
self, pv: str, timeout: float, config: ChannelConfig
) -> Channel:
meta_value, value = await asyncio.gather(
info, meta_value, value = await asyncio.gather(
cainfo(pv, timeout=timeout),
caget(pv, format=FORMAT_CTRL, timeout=timeout),
caget(pv, format=FORMAT_TIME, timeout=timeout),
)
# Put in channel id so converters can see it
channel = CAChannel(value, config, meta_value)
channel = CAChannel(value, config, meta_value, info.write)
return channel

async def put_channels(
Expand All @@ -132,14 +135,17 @@ async def subscribe_channel(
self, pv: str, config: ChannelConfig
) -> AsyncIterator[Channel]:
q: asyncio.Queue[AugmentedValue] = asyncio.Queue()
meta_value = await caget(pv, format=FORMAT_CTRL)
info, meta_value = await asyncio.gather(
cainfo(pv),
caget(pv, format=FORMAT_CTRL),
)
m = camonitor(pv, q.put, format=FORMAT_TIME)
try:
# Hold last channel for squashing identical alarms
last_channel = None
while True:
value = await q.get()
channel = CAChannel(value, config, meta_value, last_channel)
channel = CAChannel(value, config, meta_value, info.write, last_channel)
yield channel
last_channel = channel
finally:
Expand Down

0 comments on commit c404981

Please sign in to comment.